Search in sources :

Example 16 with HighlightSeverity

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

the class LocalInspectionsPass method highlightInfoFromDescriptor.

@Nullable
private HighlightInfo highlightInfoFromDescriptor(@NotNull ProblemDescriptor problemDescriptor, @NotNull HighlightInfoType highlightInfoType, @NotNull String message, String toolTip, PsiElement psiElement) {
    TextRange textRange = ((ProblemDescriptorBase) problemDescriptor).getTextRange();
    if (textRange == null || psiElement == null)
        return null;
    boolean isFileLevel = psiElement instanceof PsiFile && textRange.equals(psiElement.getTextRange());
    final HighlightSeverity severity = highlightInfoType.getSeverity(psiElement);
    TextAttributes attributes = mySeverityRegistrar.getTextAttributesBySeverity(severity);
    HighlightInfo.Builder b = HighlightInfo.newHighlightInfo(highlightInfoType).range(psiElement, textRange.getStartOffset(), textRange.getEndOffset()).description(message).severity(severity);
    if (toolTip != null)
        b.escapedToolTip(toolTip);
    if (attributes != null)
        b.textAttributes(attributes);
    if (problemDescriptor.isAfterEndOfLine())
        b.endOfLine();
    if (isFileLevel)
        b.fileLevelAnnotation();
    if (problemDescriptor.getProblemGroup() != null)
        b.problemGroup(problemDescriptor.getProblemGroup());
    return b.create();
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextRange(com.intellij.openapi.util.TextRange) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with HighlightSeverity

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

the class TrafficLightRenderer method updatePanel.

// return true if panel needs to be rebuilt
boolean updatePanel(@NotNull DaemonCodeAnalyzerStatus status, Project project) {
    progressBarsEnabled = false;
    progressBarsCompleted = null;
    statistics = "";
    passStatusesVisible = false;
    statusLabel = null;
    statusExtraLine = null;
    boolean result = false;
    if (!status.passStati.equals(new ArrayList<>(passes.keySet()))) {
        // passes set has changed
        rebuildPassesMap(status);
        result = true;
    }
    if (PowerSaveMode.isEnabled()) {
        statusLabel = "Code analysis is disabled in power save mode";
        status.errorAnalyzingFinished = true;
        icon = AllIcons.General.SafeMode;
        return result;
    }
    if (status.reasonWhyDisabled != null) {
        statusLabel = "No analysis has been performed";
        statusExtraLine = "(" + status.reasonWhyDisabled + ")";
        passStatusesVisible = true;
        progressBarsCompleted = Boolean.FALSE;
        icon = AllIcons.General.InspectionsTrafficOff;
        return result;
    }
    if (status.reasonWhySuspended != null) {
        statusLabel = "Code analysis has been suspended";
        statusExtraLine = "(" + status.reasonWhySuspended + ")";
        passStatusesVisible = true;
        progressBarsCompleted = Boolean.FALSE;
        icon = AllIcons.General.InspectionsPause;
        return result;
    }
    Icon icon = AllIcons.General.InspectionsOK;
    for (int i = status.errorCount.length - 1; i >= 0; i--) {
        if (status.errorCount[i] > 0) {
            icon = SeverityRegistrar.getSeverityRegistrar(project).getRendererIconByIndex(i);
            break;
        }
    }
    if (status.errorAnalyzingFinished) {
        boolean isDumb = project != null && DumbService.isDumb(project);
        if (isDumb) {
            statusLabel = "Shallow analysis completed";
            statusExtraLine = "Complete results will be available after indexing";
        } else {
            statusLabel = DaemonBundle.message("analysis.completed");
        }
        progressBarsCompleted = Boolean.TRUE;
    } else {
        statusLabel = DaemonBundle.message("performing.code.analysis");
        passStatusesVisible = true;
        progressBarsEnabled = true;
        progressBarsCompleted = null;
    }
    int currentSeverityErrors = 0;
    @org.intellij.lang.annotations.Language("HTML") String text = "";
    for (int i = status.errorCount.length - 1; i >= 0; i--) {
        if (status.errorCount[i] > 0) {
            final HighlightSeverity severity = SeverityRegistrar.getSeverityRegistrar(project).getSeverityByIndex(i);
            String name = status.errorCount[i] > 1 ? StringUtil.pluralize(severity.getName().toLowerCase()) : severity.getName().toLowerCase();
            text += status.errorAnalyzingFinished ? DaemonBundle.message("errors.found", status.errorCount[i], name) : DaemonBundle.message("errors.found.so.far", status.errorCount[i], name);
            text += "<br>";
            currentSeverityErrors += status.errorCount[i];
        }
    }
    if (currentSeverityErrors == 0) {
        text += status.errorAnalyzingFinished ? DaemonBundle.message("no.errors.or.warnings.found") : DaemonBundle.message("no.errors.or.warnings.found.so.far") + "<br>";
    }
    statistics = XmlStringUtil.wrapInHtml(text);
    this.icon = icon;
    return result;
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TIntArrayList(gnu.trove.TIntArrayList)

Example 18 with HighlightSeverity

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

the class TrafficLightRenderer method incErrorCount.

private void incErrorCount(RangeHighlighter highlighter, int delta) {
    Object o = highlighter.getErrorStripeTooltip();
    if (!(o instanceof HighlightInfo))
        return;
    HighlightInfo info = (HighlightInfo) o;
    HighlightSeverity infoSeverity = info.getSeverity();
    if (infoSeverity.myVal <= HighlightSeverity.INFORMATION.myVal)
        return;
    final int severityIdx = mySeverityRegistrar.getSeverityIdx(infoSeverity);
    if (severityIdx != -1) {
        errorCount[severityIdx] += delta;
    }
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity)

Example 19 with HighlightSeverity

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

the class UnusedDeclarationPresentation method exportResults.

@Override
public void exportResults(@NotNull final Element parentNode, @NotNull RefEntity refEntity, @NotNull Predicate<CommonProblemDescriptor> excludedDescriptions) {
    if (!(refEntity instanceof RefJavaElement))
        return;
    final RefFilter filter = getFilter();
    if (!getIgnoredRefElements().contains(refEntity) && filter.accepts((RefJavaElement) refEntity)) {
        refEntity = getRefManager().getRefinedElement(refEntity);
        if (!refEntity.isValid())
            return;
        RefJavaElement refElement = (RefJavaElement) refEntity;
        if (!compareVisibilities(refElement, getTool().getSharedLocalInspectionTool()))
            return;
        if (skipEntryPoints(refElement))
            return;
        Element element = refEntity.getRefManager().export(refEntity, parentNode, -1);
        if (element == null)
            return;
        @NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
        final HighlightSeverity severity = getSeverity(refElement);
        final String attributeKey = getTextAttributeKey(refElement.getRefManager().getProject(), severity, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
        problemClassElement.setAttribute("severity", severity.myName);
        problemClassElement.setAttribute("attribute_key", attributeKey);
        problemClassElement.addContent(InspectionsBundle.message("inspection.export.results.dead.code"));
        element.addContent(problemClassElement);
        @NonNls Element hintsElement = new Element("hints");
        for (UnusedDeclarationHint hint : UnusedDeclarationHint.values()) {
            @NonNls Element hintElement = new Element("hint");
            hintElement.setAttribute("value", hint.toString().toLowerCase());
            hintsElement.addContent(hintElement);
        }
        element.addContent(hintsElement);
        Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag"));
        StringBuffer buf = new StringBuffer();
        DeadHTMLComposer.appendProblemSynopsis((RefElement) refEntity, buf);
        descriptionElement.addContent(buf.toString());
        element.addContent(descriptionElement);
    }
    super.exportResults(parentNode, refEntity, excludedDescriptions);
}
Also used : RefFilter(com.intellij.codeInspection.util.RefFilter) NonNls(org.jetbrains.annotations.NonNls) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Element(org.jdom.Element)

Example 20 with HighlightSeverity

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

the class UpdateHighlightersUtil method getLayer.

private static int getLayer(@NotNull HighlightInfo info, @NotNull SeverityRegistrar severityRegistrar) {
    final HighlightSeverity severity = info.getSeverity();
    int layer;
    if (severity == HighlightSeverity.WARNING) {
        layer = HighlighterLayer.WARNING;
    } else if (severityRegistrar.compare(severity, HighlightSeverity.ERROR) >= 0) {
        layer = HighlighterLayer.ERROR;
    } else if (severity == HighlightInfoType.INJECTED_FRAGMENT_SEVERITY) {
        layer = HighlighterLayer.CARET_ROW - 1;
    } else if (severity == HighlightInfoType.ELEMENT_UNDER_CARET_SEVERITY) {
        layer = HighlighterLayer.ELEMENT_UNDER_CARET;
    } else {
        layer = HighlighterLayer.ADDITIONAL_SYNTAX;
    }
    return layer;
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity)

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