Search in sources :

Example 26 with HighlightDisplayLevel

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

the class ViewOfflineResultsAction method showOfflineView.

//used in TeamCity
@SuppressWarnings({ "WeakerAccess", "UnusedReturnValue" })
public static InspectionResultsView showOfflineView(@NotNull Project project, @Nullable final String profileName, @NotNull final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap, @NotNull String title) {
    InspectionProfileImpl profile;
    if (profileName != null) {
        profile = InspectionProjectProfileManager.getInstance(project).getProfile(profileName, false);
        if (profile == null) {
            profile = InspectionProfileManager.getInstance().getProfile(profileName, false);
        }
    } else {
        profile = null;
    }
    final InspectionProfileImpl inspectionProfile;
    if (profile != null) {
        inspectionProfile = profile;
    } else {
        inspectionProfile = new InspectionProfileImpl(profileName != null ? profileName : "Server Side") {

            @Override
            public HighlightDisplayLevel getErrorLevel(@NotNull final HighlightDisplayKey key, PsiElement element) {
                return InspectionProfileManager.getInstance().getCurrentProfile().getErrorLevel(key, element);
            }
        };
        for (String id : resMap.keySet()) {
            if (inspectionProfile.getToolsOrNull(id, project) != null) {
                inspectionProfile.enableTool(id, project);
            }
        }
    }
    return showOfflineView(project, resMap, inspectionProfile, title);
}
Also used : InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) PsiElement(com.intellij.psi.PsiElement)

Example 27 with HighlightDisplayLevel

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

Example 28 with HighlightDisplayLevel

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

the class DefaultInspectionToolPresentation method getSeverity.

public HighlightSeverity getSeverity(@NotNull RefElement element) {
    final PsiElement psiElement = element.getPointer().getContainingFile();
    if (psiElement != null) {
        final GlobalInspectionContextImpl context = getContext();
        final String shortName = getSeverityDelegateName();
        final Tools tools = context.getTools().get(shortName);
        if (tools != null) {
            for (ScopeToolState state : tools.getTools()) {
                InspectionToolWrapper toolWrapper = state.getTool();
                if (toolWrapper == getToolWrapper()) {
                    return context.getCurrentProfile().getErrorLevel(HighlightDisplayKey.find(shortName), psiElement).getSeverity();
                }
            }
        }
        final InspectionProfile profile = InspectionProjectProfileManager.getInstance(context.getProject()).getCurrentProfile();
        final HighlightDisplayLevel level = profile.getErrorLevel(HighlightDisplayKey.find(shortName), psiElement);
        return level.getSeverity();
    }
    return null;
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) PsiElement(com.intellij.psi.PsiElement)

Example 29 with HighlightDisplayLevel

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

the class InspectionTreeTailRenderer method appendTailText.

public void appendTailText(InspectionTreeNode node) {
    appendText("  ");
    final String customizedTailText = node.getCustomizedTailText();
    if (customizedTailText != null) {
        appendText("  ");
        appendText(customizedTailText, SimpleTextAttributes.GRAYED_ATTRIBUTES);
    } else {
        myItemCounter.clear();
        node.visitProblemSeverities(myItemCounter);
        if (myItemCounter.size() > MAX_LEVEL_TYPES) {
            appendText(InspectionsBundle.message("inspection.problem.descriptor.count", myItemCounter.values().stream().mapToInt(Integer::intValue).sum()) + " ", SimpleTextAttributes.GRAYED_ATTRIBUTES);
        } else {
            for (Map.Entry<HighlightDisplayLevel, Integer> entry : myItemCounter.entrySet()) {
                final HighlightDisplayLevel level = entry.getKey();
                final Integer occur = entry.getValue();
                SimpleTextAttributes attrs = SimpleTextAttributes.GRAY_ATTRIBUTES;
                attrs = attrs.derive(-1, level == HighlightDisplayLevel.ERROR && !myContext.getUIOptions().GROUP_BY_SEVERITY ? TREE_RED : TREE_GRAY, null, null);
                appendText(occur + " " + getPresentableName(level, occur > 1) + " ", attrs);
            }
        }
    }
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) SoftHashMap(com.intellij.util.containers.SoftHashMap) FactoryMap(com.intellij.util.containers.FactoryMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 30 with HighlightDisplayLevel

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

the class HighlightSeverityTest method testErrorLikeUnusedSymbol.

public void testErrorLikeUnusedSymbol() throws Exception {
    enableInspectionTool(new LocalInspectionTool() {

        @NotNull
        @Override
        public String getShortName() {
            return getDisplayName();
        }

        @NotNull
        @Override
        public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
            return new JavaElementVisitor() {

                @Override
                public void visitIdentifier(PsiIdentifier identifier) {
                    if (identifier.getText().equals("k")) {
                        holder.registerProblem(identifier, "Variable 'k' is never used");
                    }
                }
            };
        }

        @NotNull
        @Override
        public HighlightDisplayLevel getDefaultLevel() {
            return HighlightDisplayLevel.ERROR;
        }

        @Nls
        @NotNull
        @Override
        public String getDisplayName() {
            return "x";
        }

        @Nls
        @NotNull
        @Override
        public String getGroupDisplayName() {
            return getDisplayName();
        }
    });
    doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) JavaElementVisitor(com.intellij.psi.JavaElementVisitor) Nls(org.jetbrains.annotations.Nls) NonNls(org.jetbrains.annotations.NonNls) LocalInspectionToolSession(com.intellij.codeInspection.LocalInspectionToolSession) PsiIdentifier(com.intellij.psi.PsiIdentifier) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) NotNull(org.jetbrains.annotations.NotNull) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder)

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