Search in sources :

Example 1 with InspectionProfileEntry

use of com.intellij.codeInspection.InspectionProfileEntry in project kotlin by JetBrains.

the class AbstractQuickFixMultiFileTest method enableInspectionTools.

private void enableInspectionTools(@NotNull Class<?> klass) {
    List<InspectionEP> eps = ContainerUtil.newArrayList();
    ContainerUtil.addAll(eps, Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION));
    ContainerUtil.addAll(eps, Extensions.getExtensions(InspectionEP.GLOBAL_INSPECTION));
    InspectionProfileEntry tool = null;
    for (InspectionEP ep : eps) {
        if (klass.getName().equals(ep.implementationClass)) {
            tool = ep.instantiateTool();
        }
    }
    assert tool != null : "Could not find inspection tool for class: " + klass;
    enableInspectionTools(tool);
}
Also used : InspectionEP(com.intellij.codeInspection.InspectionEP) LocalInspectionEP(com.intellij.codeInspection.LocalInspectionEP) InspectionProfileEntry(com.intellij.codeInspection.InspectionProfileEntry)

Example 2 with InspectionProfileEntry

use of com.intellij.codeInspection.InspectionProfileEntry in project intellij-community by JetBrains.

the class RefJavaManagerImpl method getDeadCodeTool.

private UnusedDeclarationInspectionBase getDeadCodeTool(PsiFile file) {
    Tools tools = ((GlobalInspectionContextBase) myRefManager.getContext()).getTools().get(UnusedDeclarationInspectionBase.SHORT_NAME);
    InspectionToolWrapper toolWrapper = tools == null ? null : tools.getEnabledTool(file);
    InspectionProfileEntry tool = toolWrapper == null ? null : toolWrapper.getTool();
    return tool instanceof UnusedDeclarationInspectionBase ? (UnusedDeclarationInspectionBase) tool : null;
}
Also used : UnusedDeclarationInspectionBase(com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase) InspectionProfileEntry(com.intellij.codeInspection.InspectionProfileEntry)

Example 3 with InspectionProfileEntry

use of com.intellij.codeInspection.InspectionProfileEntry in project intellij-community by JetBrains.

the class LightInspectionTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    for (String environmentClass : getEnvironmentClasses()) {
        myFixture.addClass(environmentClass);
    }
    final InspectionProfileEntry inspection = getInspection();
    if (inspection != null) {
        myFixture.enableInspections(inspection);
        final Project project = myFixture.getProject();
        final HighlightDisplayKey displayKey = HighlightDisplayKey.find(inspection.getShortName());
        final InspectionProfileImpl currentProfile = ProjectInspectionProfileManager.getInstance(project).getCurrentProfile();
        final HighlightDisplayLevel errorLevel = currentProfile.getErrorLevel(displayKey, null);
        if (errorLevel == HighlightDisplayLevel.DO_NOT_SHOW) {
            currentProfile.setErrorLevel(displayKey, HighlightDisplayLevel.WARNING, project);
        }
    }
    Sdk sdk = ModuleRootManager.getInstance(ModuleManager.getInstance(getProject()).getModules()[0]).getSdk();
    if (JAVA_1_7.getSdk().getName().equals(sdk == null ? null : sdk.getName())) {
        PsiClass object = JavaPsiFacade.getInstance(getProject()).findClass("java.lang.Object", GlobalSearchScope.allScope(getProject()));
        assertNotNull(object);
        PsiClass component = JavaPsiFacade.getInstance(getProject()).findClass("java.awt.Component", GlobalSearchScope.allScope(getProject()));
        assertNotNull(component);
    }
}
Also used : Project(com.intellij.openapi.project.Project) InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) PsiClass(com.intellij.psi.PsiClass) InspectionProfileEntry(com.intellij.codeInspection.InspectionProfileEntry) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 4 with InspectionProfileEntry

use of com.intellij.codeInspection.InspectionProfileEntry in project intellij-community by JetBrains.

the class InspectionProfileImpl method modifyToolSettings.

@Override
public <T extends InspectionProfileEntry> void modifyToolSettings(@NotNull final Key<T> shortNameKey, @NotNull final PsiElement psiElement, @NotNull final Consumer<T> toolConsumer) {
    modifyProfile(model -> {
        InspectionProfileEntry tool = model.getUnwrappedTool(shortNameKey.toString(), psiElement);
        toolConsumer.consume((T) tool);
    });
}
Also used : InspectionProfileEntry(com.intellij.codeInspection.InspectionProfileEntry)

Example 5 with InspectionProfileEntry

use of com.intellij.codeInspection.InspectionProfileEntry in project intellij-community by JetBrains.

the class LightInspectionTestCase method getBasePath.

@Override
protected String getBasePath() {
    final InspectionProfileEntry inspection = getInspection();
    assertNotNull("File-based tests should either return an inspection or override this method", inspection);
    final String className = inspection.getClass().getName();
    final String[] words = className.split("\\.");
    final StringBuilder basePath = new StringBuilder("/plugins/InspectionGadgets/test/");
    final int lastWordIndex = words.length - 1;
    for (int i = 0; i < lastWordIndex; i++) {
        String word = words[i];
        if (word.equals("ig")) {
            //noinspection SpellCheckingInspection
            word = "igtest";
        }
        basePath.append(word).append('/');
    }
    String lastWord = words[lastWordIndex];
    lastWord = StringUtil.trimEnd(lastWord, "Inspection");
    final int length = lastWord.length();
    boolean upperCase = false;
    for (int i = 0; i < length; i++) {
        final char ch = lastWord.charAt(i);
        if (Character.isUpperCase(ch)) {
            if (!upperCase) {
                upperCase = true;
                if (i != 0) {
                    basePath.append('_');
                }
            }
            basePath.append(Character.toLowerCase(ch));
        } else {
            upperCase = false;
            basePath.append(ch);
        }
    }
    return basePath.toString();
}
Also used : InspectionProfileEntry(com.intellij.codeInspection.InspectionProfileEntry)

Aggregations

InspectionProfileEntry (com.intellij.codeInspection.InspectionProfileEntry)5 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)1 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)1 InspectionEP (com.intellij.codeInspection.InspectionEP)1 LocalInspectionEP (com.intellij.codeInspection.LocalInspectionEP)1 UnusedDeclarationInspectionBase (com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase)1 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 PsiClass (com.intellij.psi.PsiClass)1