Search in sources :

Example 21 with HighlightSeverity

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

the class SeverityRegistrar method writeExternal.

public void writeExternal(Element element) {
    List<HighlightSeverity> list = getOrderAsList(getOrderMap());
    for (HighlightSeverity severity : list) {
        Element info = new Element(INFO_TAG);
        String severityName = severity.getName();
        final SeverityBasedTextAttributes infoType = getAttributesBySeverity(severity);
        if (infoType != null) {
            infoType.writeExternal(info);
            final Color color = myRendererColors.get(severityName);
            if (color != null) {
                info.setAttribute(COLOR_ATTRIBUTE, Integer.toString(color.getRGB() & 0xFFFFFF, 16));
            }
            element.addContent(info);
        }
    }
    if (myReadOrder != null && !myReadOrder.isEmpty()) {
        myReadOrder.writeExternal(element);
    } else if (!getDefaultOrder().equals(list)) {
        final JDOMExternalizableStringList ext = new JDOMExternalizableStringList(Collections.nCopies(getOrderMap().size(), ""));
        getOrderMap().forEachEntry(new TObjectIntProcedure<HighlightSeverity>() {

            @Override
            public boolean execute(HighlightSeverity orderSeverity, int oIdx) {
                ext.set(oIdx, orderSeverity.getName());
                return true;
            }
        });
        ext.writeExternal(element);
    }
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) JDOMExternalizableStringList(com.intellij.openapi.util.JDOMExternalizableStringList) Element(org.jdom.Element) TObjectIntProcedure(gnu.trove.TObjectIntProcedure)

Example 22 with HighlightSeverity

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

the class SeverityRegistrar method getRendererIconByIndex.

public Icon getRendererIconByIndex(int i) {
    final HighlightSeverity severity = getSeverityByIndex(i);
    HighlightDisplayLevel level = HighlightDisplayLevel.find(severity);
    if (level != null) {
        return level.getIcon();
    }
    return HighlightDisplayLevel.createIconByMask(myRendererColors.get(severity.getName()));
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel)

Example 23 with HighlightSeverity

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

the class SeverityRegistrar method ensureAllStandardIncluded.

private OrderMap ensureAllStandardIncluded(List<HighlightSeverity> read, final List<HighlightSeverity> knownSeverities) {
    OrderMap orderMap = fromList(read);
    if (orderMap.isEmpty()) {
        orderMap = fromList(knownSeverities);
    } else {
        //enforce include all known
        List<HighlightSeverity> list = getOrderAsList(orderMap);
        for (int i = 0; i < knownSeverities.size(); i++) {
            HighlightSeverity stdSeverity = knownSeverities.get(i);
            if (!list.contains(stdSeverity)) {
                for (int oIdx = 0; oIdx < list.size(); oIdx++) {
                    HighlightSeverity orderSeverity = list.get(oIdx);
                    HighlightInfoType type = STANDARD_SEVERITIES.get(orderSeverity.getName());
                    if (type != null && knownSeverities.indexOf(type.getSeverity(null)) > i) {
                        list.add(oIdx, stdSeverity);
                        myReadOrder = null;
                        break;
                    }
                }
            }
        }
        orderMap = fromList(list);
    }
    return orderMap;
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity)

Example 24 with HighlightSeverity

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

the class ApplicationInspectionProfileManager method registerProvidedSeverities.

// It should be public to be available from Upsource
public static void registerProvidedSeverities() {
    for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
        for (HighlightInfoType t : provider.getSeveritiesHighlightInfoTypes()) {
            HighlightSeverity highlightSeverity = t.getSeverity(null);
            SeverityRegistrar.registerStandard(t, highlightSeverity);
            TextAttributesKey attributesKey = t.getAttributesKey();
            Icon icon = t instanceof HighlightInfoType.Iconable ? ((HighlightInfoType.Iconable) t).getIcon() : null;
            HighlightDisplayLevel.registerSeverity(highlightSeverity, attributesKey, icon);
        }
    }
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) SeveritiesProvider(com.intellij.codeInsight.daemon.impl.SeveritiesProvider) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType)

Example 25 with HighlightSeverity

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

the class DefaultInspectionToolPresentation method exportResults.

private void exportResults(@NotNull final CommonProblemDescriptor[] descriptors, @NotNull RefEntity refEntity, @NotNull Element parentNode, @NotNull Predicate<CommonProblemDescriptor> isDescriptorExcluded) {
    for (CommonProblemDescriptor descriptor : descriptors) {
        if (isDescriptorExcluded.test(descriptor))
            continue;
        @NonNls final String template = descriptor.getDescriptionTemplate();
        int line = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getLineNumber() : -1;
        final PsiElement psiElement = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : null;
        @NonNls String problemText = StringUtil.replace(StringUtil.replace(template, "#ref", psiElement != null ? ProblemDescriptorUtil.extractHighlightedText(descriptor, psiElement) : ""), " #loc ", " ");
        Element element = refEntity.getRefManager().export(refEntity, parentNode, line);
        if (element == null)
            return;
        @NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
        problemClassElement.addContent(myToolWrapper.getDisplayName());
        final HighlightSeverity severity;
        if (refEntity instanceof RefElement) {
            final RefElement refElement = (RefElement) refEntity;
            severity = getSeverity(refElement);
        } else {
            final InspectionProfile profile = InspectionProjectProfileManager.getInstance(getContext().getProject()).getCurrentProfile();
            final HighlightDisplayLevel level = profile.getErrorLevel(HighlightDisplayKey.find(myToolWrapper.getShortName()), psiElement);
            severity = level.getSeverity();
        }
        if (severity != null) {
            ProblemHighlightType problemHighlightType = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getHighlightType() : ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
            final String attributeKey = getTextAttributeKey(getRefManager().getProject(), severity, problemHighlightType);
            problemClassElement.setAttribute("severity", severity.myName);
            problemClassElement.setAttribute("attribute_key", attributeKey);
        }
        element.addContent(problemClassElement);
        if (myToolWrapper instanceof GlobalInspectionToolWrapper) {
            final GlobalInspectionTool globalInspectionTool = ((GlobalInspectionToolWrapper) myToolWrapper).getTool();
            final QuickFix[] fixes = descriptor.getFixes();
            if (fixes != null) {
                @NonNls Element hintsElement = new Element("hints");
                for (QuickFix fix : fixes) {
                    final String hint = globalInspectionTool.getHint(fix);
                    if (hint != null) {
                        @NonNls Element hintElement = new Element("hint");
                        hintElement.setAttribute("value", hint);
                        hintsElement.addContent(hintElement);
                    }
                }
                element.addContent(hintsElement);
            }
        }
        try {
            Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag"));
            descriptionElement.addContent(problemText);
            element.addContent(descriptionElement);
        } catch (IllegalDataException e) {
            //noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr
            System.out.println("Cannot save results for " + refEntity.getName() + ", inspection which caused problem: " + myToolWrapper.getShortName());
        }
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) PsiElement(com.intellij.psi.PsiElement) IllegalDataException(org.jdom.IllegalDataException)

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