Search in sources :

Example 16 with HighlightDisplayLevel

use of com.intellij.codeHighlighting.HighlightDisplayLevel in project kotlin by JetBrains.

the class AndroidLintInspectionBase method getDefaultLevel.

@NotNull
@Override
public HighlightDisplayLevel getDefaultLevel() {
    final Severity defaultSeverity = myIssue.getDefaultSeverity();
    if (defaultSeverity == null) {
        return HighlightDisplayLevel.WARNING;
    }
    final HighlightDisplayLevel displayLevel = toHighlightDisplayLevel(defaultSeverity);
    return displayLevel != null ? displayLevel : HighlightDisplayLevel.WARNING;
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with HighlightDisplayLevel

use of com.intellij.codeHighlighting.HighlightDisplayLevel in project android by JetBrains.

the class AndroidLintInspectionBase method getDefaultLevel.

@NotNull
@Override
public HighlightDisplayLevel getDefaultLevel() {
    final Severity defaultSeverity = myIssue.getDefaultSeverity();
    if (defaultSeverity == null) {
        return HighlightDisplayLevel.WARNING;
    }
    final HighlightDisplayLevel displayLevel = toHighlightDisplayLevel(defaultSeverity);
    return displayLevel != null ? displayLevel : HighlightDisplayLevel.WARNING;
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with HighlightDisplayLevel

use of com.intellij.codeHighlighting.HighlightDisplayLevel in project android by JetBrains.

the class AndroidLintUtil method getHighlighLevelAndInspection.

@Nullable
public static Pair<AndroidLintInspectionBase, HighlightDisplayLevel> getHighlighLevelAndInspection(@NotNull Project project, @NotNull Issue issue, @NotNull PsiElement context) {
    final String inspectionShortName = AndroidLintInspectionBase.getInspectionShortNameByIssue(project, issue);
    if (inspectionShortName == null) {
        return null;
    }
    final HighlightDisplayKey key = HighlightDisplayKey.find(inspectionShortName);
    if (key == null) {
        return null;
    }
    final InspectionProfile profile = InspectionProjectProfileManager.getInstance(context.getProject()).getCurrentProfile();
    if (!profile.isToolEnabled(key, context)) {
        if (!issue.isEnabledByDefault()) {
        // Lint will skip issues (and not report them) for issues that have been disabled,
        // except for those issues that are explicitly enabled via Gradle. Therefore, if
        // we get this far, lint has found this issue to be explicitly enabled, so we let
        // that setting override a local enabled/disabled state in the IDE profile.
        } else {
            return null;
        }
    }
    final AndroidLintInspectionBase inspection = (AndroidLintInspectionBase) profile.getUnwrappedTool(inspectionShortName, context);
    if (inspection == null)
        return null;
    final HighlightDisplayLevel errorLevel = profile.getErrorLevel(key, context);
    return Pair.create(inspection, errorLevel != null ? errorLevel : HighlightDisplayLevel.WARNING);
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) InspectionProfile(com.intellij.codeInspection.InspectionProfile) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with HighlightDisplayLevel

use of com.intellij.codeHighlighting.HighlightDisplayLevel in project android by JetBrains.

the class NlLintHighlightingPass method getAnnotations.

@NotNull
private static LintAnnotationsModel getAnnotations(@NotNull NlModel model, @NotNull ProgressIndicator progress) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    LintAnnotationsModel lintModel = new LintAnnotationsModel();
    XmlFile xmlFile = model.getFile();
    AndroidLintExternalAnnotator annotator = new AndroidLintExternalAnnotator();
    State state = annotator.collectInformation(xmlFile);
    if (state != null) {
        state = annotator.doAnnotate(state);
    }
    if (state == null) {
        return lintModel;
    }
    for (ProblemData problemData : state.getProblems()) {
        if (progress.isCanceled()) {
            break;
        }
        TextRange range = problemData.getTextRange();
        final PsiElement startElement = xmlFile.findElementAt(range.getStartOffset());
        final PsiElement endElement = xmlFile.findElementAt(range.getEndOffset());
        if (startElement == null || endElement == null) {
            continue;
        }
        NlComponent component = model.findViewByPsi(startElement);
        if (component == null) {
            continue;
        }
        Issue issue = problemData.getIssue();
        Pair<AndroidLintInspectionBase, HighlightDisplayLevel> pair = AndroidLintUtil.getHighlighLevelAndInspection(xmlFile.getProject(), issue, xmlFile);
        if (pair == null) {
            continue;
        }
        AndroidLintInspectionBase inspection = pair.getFirst();
        if (inspection == null) {
            continue;
        }
        HighlightDisplayLevel level = pair.getSecond();
        HighlightDisplayKey key = HighlightDisplayKey.find(inspection.getShortName());
        if (key == null) {
            continue;
        }
        lintModel.addIssue(component, issue, problemData.getMessage(), inspection, level, startElement, endElement);
    }
    return lintModel;
}
Also used : Issue(com.android.tools.lint.detector.api.Issue) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) XmlFile(com.intellij.psi.xml.XmlFile) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) TextRange(com.intellij.openapi.util.TextRange) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with HighlightDisplayLevel

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

the class RegExpInspectionTestCase method highlightTest.

protected void highlightTest(@Language("RegExp") String code) {
    final LocalInspectionTool inspection = getInspection();
    myFixture.enableInspections(inspection);
    final HighlightDisplayKey displayKey = HighlightDisplayKey.find(inspection.getShortName());
    if (displayKey != null) {
        final Project project = myFixture.getProject();
        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);
        }
    }
    myFixture.configureByText(RegExpFileType.INSTANCE, code);
    myFixture.testHighlighting();
}
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) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool)

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