Search in sources :

Example 1 with InspectionEP

use of com.intellij.codeInspection.InspectionEP 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 InspectionEP

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

the class InspectionProfileImpl method addTool.

public void addTool(@Nullable Project project, @NotNull InspectionToolWrapper toolWrapper, @NotNull Map<String, List<String>> dependencies) {
    final String shortName = toolWrapper.getShortName();
    HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
    if (key == null) {
        final InspectionEP extension = toolWrapper.getExtension();
        Computable<String> computable = extension == null ? new Computable.PredefinedValueComputable<>(toolWrapper.getDisplayName()) : extension::getDisplayName;
        if (toolWrapper instanceof LocalInspectionToolWrapper) {
            key = HighlightDisplayKey.register(shortName, computable, toolWrapper.getID(), ((LocalInspectionToolWrapper) toolWrapper).getAlternativeID());
        } else {
            key = HighlightDisplayKey.register(shortName, computable);
        }
    }
    if (key == null) {
        LOG.error(shortName + " ; number of initialized tools: " + myTools.size());
        return;
    }
    HighlightDisplayLevel baseLevel = myBaseProfile != null && myBaseProfile.getToolsOrNull(shortName, project) != null ? myBaseProfile.getErrorLevel(key, project) : HighlightDisplayLevel.DO_NOT_SHOW;
    HighlightDisplayLevel defaultLevel = toolWrapper.getDefaultLevel();
    HighlightDisplayLevel level = baseLevel.getSeverity().compareTo(defaultLevel.getSeverity()) > 0 ? baseLevel : defaultLevel;
    boolean enabled = myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : toolWrapper.isEnabledByDefault();
    final ToolsImpl toolsList = new ToolsImpl(toolWrapper, level, !myLockedProfile && enabled, enabled);
    final Element element = myUninitializedSettings.remove(shortName);
    try {
        if (element != null) {
            getPathMacroManager().expandPaths(element);
            toolsList.readExternal(element, getProfileManager(), dependencies);
        } else if (!myUninitializedSettings.containsKey(InspectionElementsMergerBase.getMergedMarkerName(shortName))) {
            final InspectionElementsMergerBase merger = getMerger(shortName);
            Element merged = merger == null ? null : merger.merge(myUninitializedSettings);
            if (merged != null) {
                getPathMacroManager().expandPaths(merged);
                toolsList.readExternal(merged, getProfileManager(), dependencies);
            } else if (isProfileLocked()) {
                // https://youtrack.jetbrains.com/issue/IDEA-158936
                toolsList.setEnabled(false);
                if (toolsList.getNonDefaultTools() == null) {
                    toolsList.getDefaultState().setEnabled(false);
                }
            }
        }
    } catch (InvalidDataException e) {
        LOG.error("Can't read settings for " + toolWrapper, e);
    }
    myTools.put(shortName, toolsList);
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) InspectionEP(com.intellij.codeInspection.InspectionEP)

Example 3 with InspectionEP

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

the class InspectionTestCase method getUnusedDeclarationWrapper.

protected static GlobalInspectionToolWrapper getUnusedDeclarationWrapper() {
    InspectionEP ep = new InspectionEP();
    ep.presentation = UnusedDeclarationPresentation.class.getName();
    ep.implementationClass = UnusedDeclarationInspection.class.getName();
    ep.shortName = UnusedDeclarationInspectionBase.SHORT_NAME;
    ep.displayName = UnusedDeclarationInspectionBase.DISPLAY_NAME;
    return new GlobalInspectionToolWrapper(ep);
}
Also used : InspectionEP(com.intellij.codeInspection.InspectionEP) UnusedDeclarationPresentation(com.intellij.codeInspection.deadCode.UnusedDeclarationPresentation) UnusedDeclarationInspection(com.intellij.codeInspection.deadCode.UnusedDeclarationInspection)

Example 4 with InspectionEP

use of com.intellij.codeInspection.InspectionEP in project android by JetBrains.

the class AndroidInspectionsTest method getUnusedDeclarationWrapper.

private static GlobalInspectionToolWrapper getUnusedDeclarationWrapper() {
    final InspectionEP ep = new InspectionEP();
    ep.presentation = UnusedDeclarationPresentation.class.getName();
    ep.implementationClass = UnusedDeclarationInspection.class.getName();
    ep.shortName = UnusedDeclarationInspectionBase.SHORT_NAME;
    UnusedDeclarationInspection tool = new UnusedDeclarationInspection(true);
    return new GlobalInspectionToolWrapper(tool, ep);
}
Also used : GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) InspectionEP(com.intellij.codeInspection.InspectionEP) UnusedDeclarationPresentation(com.intellij.codeInspection.deadCode.UnusedDeclarationPresentation) UnusedDeclarationInspection(com.intellij.codeInspection.deadCode.UnusedDeclarationInspection)

Aggregations

InspectionEP (com.intellij.codeInspection.InspectionEP)4 UnusedDeclarationInspection (com.intellij.codeInspection.deadCode.UnusedDeclarationInspection)2 UnusedDeclarationPresentation (com.intellij.codeInspection.deadCode.UnusedDeclarationPresentation)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)1 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)1 InspectionProfileEntry (com.intellij.codeInspection.InspectionProfileEntry)1 LocalInspectionEP (com.intellij.codeInspection.LocalInspectionEP)1 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)1 PsiElement (com.intellij.psi.PsiElement)1 Element (org.jdom.Element)1