Search in sources :

Example 11 with HighlightDisplayLevel

use of com.intellij.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.

the class SingleInspectionProfilePanel method compoundPopup.

private JPopupMenu compoundPopup() {
    final DefaultActionGroup group = new DefaultActionGroup();
    final SeverityRegistrar severityRegistrar = myProfile.getProfileManager().getOwnSeverityRegistrar();
    for (HighlightSeverity severity : LevelChooserAction.getSeverities(severityRegistrar, includeDoNotShow())) {
        final HighlightDisplayLevel level = HighlightDisplayLevel.find(severity);
        group.add(new AnAction(renderSeverity(severity), renderSeverity(severity), level.getIcon()) {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                setNewHighlightingLevel(level);
            }

            @Override
            public boolean isDumbAware() {
                return true;
            }
        });
    }
    group.add(Separator.getInstance());
    ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group);
    return menu.getComponent();
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) SeverityRegistrar(com.intellij.codeInsight.daemon.impl.SeverityRegistrar)

Example 12 with HighlightDisplayLevel

use of com.intellij.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.

the class InspectionProfileImpl method getErrorLevel.

@Override
public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey inspectionToolKey, PsiElement element) {
    Project project = element == null ? null : element.getProject();
    final ToolsImpl tools = getToolsOrNull(inspectionToolKey.toString(), project);
    HighlightDisplayLevel level = tools != null ? tools.getLevel(element) : HighlightDisplayLevel.WARNING;
    if (!getProfileManager().getOwnSeverityRegistrar().isSeverityValid(level.getSeverity().getName())) {
        level = HighlightDisplayLevel.WARNING;
        setErrorLevel(inspectionToolKey, level, project);
    }
    return level;
}
Also used : Project(com.intellij.openapi.project.Project) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel)

Example 13 with HighlightDisplayLevel

use of com.intellij.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.

the class InspectionProfileImpl method convert.

public void convert(@NotNull Element element, @NotNull Project project) {
    final Element scopes = element.getChild("scopes");
    if (scopes == null) {
        return;
    }
    initInspectionTools(project);
    for (Element scopeElement : scopes.getChildren(SCOPE)) {
        final String profile = scopeElement.getAttributeValue(PROFILE);
        InspectionProfileImpl inspectionProfile = profile == null ? null : getProfileManager().getProfile(profile);
        NamedScope scope = inspectionProfile == null ? null : getProfileManager().getScopesManager().getScope(scopeElement.getAttributeValue(NAME));
        if (scope == null) {
            continue;
        }
        for (InspectionToolWrapper toolWrapper : inspectionProfile.getInspectionTools(null)) {
            final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
            try {
                InspectionToolWrapper toolWrapperCopy = copyToolSettings(toolWrapper);
                HighlightDisplayLevel errorLevel = inspectionProfile.getErrorLevel(key, null, project);
                getTools(toolWrapper.getShortName(), project).addTool(scope, toolWrapperCopy, inspectionProfile.isToolEnabled(key), errorLevel);
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    }
    reduceConvertedScopes();
}
Also used : NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 14 with HighlightDisplayLevel

use of com.intellij.codeHighlighting.HighlightDisplayLevel 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 15 with HighlightDisplayLevel

use of com.intellij.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.

the class WebReferencesAnnotatorBase method apply.

@Override
public void apply(@NotNull PsiFile file, MyInfo[] infos, @NotNull AnnotationHolder holder) {
    if (infos == null || infos.length == 0) {
        return;
    }
    final HighlightDisplayLevel displayLevel = getHighlightDisplayLevel(file);
    for (MyInfo info : infos) {
        if (!info.myResult) {
            final PsiElement element = info.myAnchor.retrieve();
            if (element != null) {
                final int start = element.getTextRange().getStartOffset();
                final TextRange range = new TextRange(start + info.myRangeInElement.getStartOffset(), start + info.myRangeInElement.getEndOffset());
                final String message = getErrorMessage(info.myUrl);
                final Annotation annotation;
                if (displayLevel == HighlightDisplayLevel.ERROR) {
                    annotation = holder.createErrorAnnotation(range, message);
                } else if (displayLevel == HighlightDisplayLevel.WARNING) {
                    annotation = holder.createWarningAnnotation(range, message);
                } else if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) {
                    annotation = holder.createInfoAnnotation(range, message);
                } else {
                    annotation = holder.createWarningAnnotation(range, message);
                }
                for (IntentionAction action : getQuickFixes()) {
                    annotation.registerFix(action);
                }
            }
        }
    }
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) Annotation(com.intellij.lang.annotation.Annotation)

Aggregations

HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)34 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)14 PsiElement (com.intellij.psi.PsiElement)13 Project (com.intellij.openapi.project.Project)7 Element (org.jdom.Element)6 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)5 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)5 NotNull (org.jetbrains.annotations.NotNull)5 SeverityRegistrar (com.intellij.codeInsight.daemon.impl.SeverityRegistrar)4 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)4 Annotation (com.intellij.lang.annotation.Annotation)4 Issue (com.android.tools.lint.detector.api.Issue)3 InspectionProfile (com.intellij.codeInspection.InspectionProfile)3 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)3 NamedScope (com.intellij.psi.search.scope.packageSet.NamedScope)3 LinkedHashMap (com.intellij.util.containers.hash.LinkedHashMap)3 Nullable (org.jetbrains.annotations.Nullable)3 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 TextRange (com.intellij.openapi.util.TextRange)2