Search in sources :

Example 26 with HighlightSeverity

use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.

the class LevelChooserAction method createPopupActionGroup.

@NotNull
@Override
public DefaultActionGroup createPopupActionGroup(final JComponent anchor) {
    final DefaultActionGroup group = new DefaultActionGroup();
    for (final HighlightSeverity severity : getSeverities(mySeverityRegistrar, myIncludeDoNotShow)) {
        final HighlightSeverityAction action = new HighlightSeverityAction(severity);
        if (myChosen == null) {
            setChosen(action.getSeverity());
        }
        group.add(action);
    }
    group.addSeparator();
    group.add(new DumbAwareAction("Edit severities...") {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            final SeverityEditorDialog dlg = new SeverityEditorDialog(anchor, myChosen, mySeverityRegistrar, true);
            if (dlg.showAndGet()) {
                final HighlightInfoType type = dlg.getSelectedType();
                if (type != null) {
                    final HighlightSeverity severity = type.getSeverity(null);
                    setChosen(severity);
                    onChosen(severity);
                }
            }
        }
    });
    return group;
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) SeverityEditorDialog(com.intellij.codeInspection.ex.SeverityEditorDialog) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with HighlightSeverity

use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.

the class InspectionFilterAction method tune.

private void tune(InspectionProfileImpl profile, Project project) {
    addAction(new ResetFilterAction());
    addSeparator();
    if (ApplicationNamesInfo.getInstance().getProductName().contains("IDEA")) {
        // minor IDEs don't have "New in XXX" in inspection descriptions
        addAction(new ShowNewInspectionsAction());
    }
    addSeparator();
    addAction(new ShowEnabledOrDisabledInspectionsAction(true));
    addAction(new ShowEnabledOrDisabledInspectionsAction(false));
    addAction(new ShowOnlyModifiedInspectionsAction());
    addSeparator();
    for (final HighlightSeverity severity : LevelChooserAction.getSeverities(mySeverityRegistrar)) {
        add(new ShowWithSpecifiedSeverityInspectionsAction(severity));
    }
    addSeparator();
    final Set<String> languageIds = new THashSet<>();
    for (ScopeToolState state : profile.getDefaultStates(project)) {
        languageIds.add(state.getTool().getLanguage());
    }
    final List<Language> languages = new SmartList<>();
    for (String id : languageIds) {
        if (id != null) {
            final Language language = Language.findLanguageByID(id);
            if (language != null) {
                languages.add(language);
            }
        }
    }
    if (!languages.isEmpty()) {
        final DefaultActionGroup languageActionGroupParent = new DefaultActionGroup("Filter by Language", languages.size() >= MIN_LANGUAGE_COUNT_TO_WRAP);
        add(languageActionGroupParent);
        Collections.sort(languages, Comparator.comparing(Language::getDisplayName));
        for (Language language : languages) {
            languageActionGroupParent.add(new LanguageFilterAction(language));
        }
        languageActionGroupParent.add(new LanguageFilterAction(null));
        addSeparator();
    }
    add(new ShowAvailableOnlyOnAnalyzeInspectionsAction());
    add(new ShowOnlyCleanupInspectionsAction());
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) ScopeToolState(com.intellij.codeInspection.ex.ScopeToolState) THashSet(gnu.trove.THashSet) Language(com.intellij.lang.Language) SmartList(com.intellij.util.SmartList)

Example 28 with HighlightSeverity

use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.

the class InspectionToolsConfigurable method importInspectionProfile.

public static InspectionProfileImpl importInspectionProfile(@NotNull Element rootElement, @NotNull BaseInspectionProfileManager profileManager, @NotNull Project project) {
    InspectionProfileImpl profile = new InspectionProfileImpl("TempProfile", InspectionToolRegistrar.getInstance(), profileManager);
    if (Comparing.strEqual(rootElement.getName(), "component")) {
        //import right from .idea/inspectProfiles/xxx.xml
        rootElement = rootElement.getChildren().get(0);
    }
    final Set<String> levels = new HashSet<>();
    for (Element inspectElement : rootElement.getChildren("inspection_tool")) {
        addLevelIfNotNull(levels, inspectElement);
        for (Element s : inspectElement.getChildren("scope")) {
            addLevelIfNotNull(levels, s);
        }
    }
    for (Iterator<String> iterator = levels.iterator(); iterator.hasNext(); ) {
        String level = iterator.next();
        if (profileManager.getOwnSeverityRegistrar().getSeverity(level) != null) {
            iterator.remove();
        }
    }
    if (!levels.isEmpty()) {
        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            if (Messages.showYesNoDialog(project, "Undefined severities detected: " + StringUtil.join(levels, ", ") + ". Do you want to create them?", "Warning", Messages.getWarningIcon()) == Messages.YES) {
                for (String level : levels) {
                    final TextAttributes textAttributes = CodeInsightColors.WARNINGS_ATTRIBUTES.getDefaultAttributes();
                    HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl(new HighlightSeverity(level, 50), TextAttributesKey.createTextAttributesKey(level));
                    profileManager.getOwnSeverityRegistrar().registerSeverity(new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes.clone(), info), textAttributes.getErrorStripeColor());
                }
            }
        } else {
            throw new AssertionError("All of levels must exist in unit-test mode, but actual not exist levels = " + levels);
        }
    }
    profile.readExternal(rootElement);
    profile.setProjectLevel(false);
    profile.initInspectionTools(project);
    return profile;
}
Also used : InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Element(org.jdom.Element) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SeverityRegistrar(com.intellij.codeInsight.daemon.impl.SeverityRegistrar) HashSet(java.util.HashSet)

Example 29 with HighlightSeverity

use of com.intellij.lang.annotation.HighlightSeverity in project kotlin by JetBrains.

the class AndroidLintExternalAnnotator method createAnnotation.

@SuppressWarnings("deprecation")
@NotNull
private Annotation createAnnotation(@NotNull AnnotationHolder holder, @NotNull String message, @NotNull TextRange range, @NotNull HighlightDisplayLevel displayLevel, @NotNull Issue issue) {
    // Convert from inspection severity to annotation severity
    HighlightSeverity severity;
    if (displayLevel == HighlightDisplayLevel.ERROR) {
        severity = HighlightSeverity.ERROR;
    } else if (displayLevel == HighlightDisplayLevel.WARNING) {
        severity = HighlightSeverity.WARNING;
    } else if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) {
        severity = HighlightSeverity.WEAK_WARNING;
    } else if (displayLevel == HighlightDisplayLevel.INFO) {
        severity = HighlightSeverity.INFO;
    } else {
        severity = HighlightSeverity.WARNING;
    }
    String link = " <a " + "href=\"#lint/" + issue.getId() + "\"" + (UIUtil.isUnderDarcula() ? " color=\"7AB4C9\" " : "") + ">" + DaemonBundle.message("inspection.extended.description") + "</a> " + getShowMoreShortCut();
    String tooltip = XmlStringUtil.wrapInHtml(RAW.convertTo(message, HTML) + link);
    return holder.createAnnotation(severity, range, message, tooltip);
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with HighlightSeverity

use of com.intellij.lang.annotation.HighlightSeverity in project intellij-community by JetBrains.

the class DomElementsHighlightingUtil method createAnnotation.

@Nullable
public static Annotation createAnnotation(final DomElementProblemDescriptor problemDescriptor) {
    return createProblemDescriptors(problemDescriptor, s -> {
        String text = problemDescriptor.getDescriptionTemplate();
        if (StringUtil.isEmpty(text))
            text = null;
        final HighlightSeverity severity = problemDescriptor.getHighlightSeverity();
        TextRange range = s.first;
        if (text == null)
            range = TextRange.from(range.getStartOffset(), 0);
        range = range.shiftRight(s.second.getTextRange().getStartOffset());
        final Annotation annotation = createAnnotation(severity, range, text);
        if (problemDescriptor instanceof DomElementResolveProblemDescriptor) {
            annotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
        }
        for (LocalQuickFix fix : problemDescriptor.getFixes()) {
            if (fix instanceof IntentionAction)
                annotation.registerFix((IntentionAction) fix);
        }
        return annotation;
    });
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) TextRange(com.intellij.openapi.util.TextRange) Annotation(com.intellij.lang.annotation.Annotation) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)31 Element (org.jdom.Element)8 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)7 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)6 NotNull (org.jetbrains.annotations.NotNull)6 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)5 SeverityRegistrar (com.intellij.codeInsight.daemon.impl.SeverityRegistrar)5 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)5 Nullable (org.jetbrains.annotations.Nullable)4 Annotation (com.intellij.lang.annotation.Annotation)3 TextRange (com.intellij.openapi.util.TextRange)3 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 Document (com.intellij.openapi.editor.Document)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 Project (com.intellij.openapi.project.Project)2 JDOMExternalizableStringList (com.intellij.openapi.util.JDOMExternalizableStringList)2 PsiElement (com.intellij.psi.PsiElement)2 THashSet (gnu.trove.THashSet)2 NonNls (org.jetbrains.annotations.NonNls)2