Search in sources :

Example 41 with HighlightDisplayKey

use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project intellij-community by JetBrains.

the class XmlImportOptimizer method processFile.

@NotNull
@Override
public CollectingInfoRunnable processFile(final PsiFile file) {
    return new CollectingInfoRunnable() {

        int myRemovedNameSpaces = 0;

        @Override
        public void run() {
            XmlFile xmlFile = (XmlFile) file;
            Project project = xmlFile.getProject();
            HighlightDisplayKey key = HighlightDisplayKey.find(myInspection.getShortName());
            if (!InspectionProjectProfileManager.getInstance(project).getCurrentProfile().isToolEnabled(key, xmlFile))
                return;
            ProblemsHolder holder = new ProblemsHolder(InspectionManager.getInstance(project), xmlFile, false);
            final XmlElementVisitor visitor = (XmlElementVisitor) myInspection.buildVisitor(holder, false);
            new PsiRecursiveElementVisitor() {

                @Override
                public void visitElement(PsiElement element) {
                    if (element instanceof XmlAttribute) {
                        visitor.visitXmlAttribute((XmlAttribute) element);
                    } else {
                        super.visitElement(element);
                    }
                }
            }.visitFile(xmlFile);
            ProblemDescriptor[] results = holder.getResultsArray();
            List<ProblemDescriptor> list = ContainerUtil.filter(results, myCondition);
            Map<XmlUnusedNamespaceInspection.RemoveNamespaceDeclarationFix, ProblemDescriptor> fixes = new LinkedHashMap<>();
            for (ProblemDescriptor result : list) {
                for (QuickFix fix : result.getFixes()) {
                    if (fix instanceof XmlUnusedNamespaceInspection.RemoveNamespaceDeclarationFix) {
                        fixes.put((XmlUnusedNamespaceInspection.RemoveNamespaceDeclarationFix) fix, result);
                    }
                }
            }
            SmartPsiElementPointer<XmlTag> pointer = null;
            for (Map.Entry<XmlUnusedNamespaceInspection.RemoveNamespaceDeclarationFix, ProblemDescriptor> fix : fixes.entrySet()) {
                pointer = fix.getKey().doFix(project, fix.getValue(), false);
                myRemovedNameSpaces++;
            }
            if (pointer != null) {
                XmlUnusedNamespaceInspection.RemoveNamespaceDeclarationFix.reformatStartTag(project, pointer);
            }
        }

        @Nullable
        @Override
        public String getUserNotificationInfo() {
            return myRemovedNameSpaces > 0 ? "Removed " + myRemovedNameSpaces + " namespace" + (myRemovedNameSpaces > 1 ? "s" : "") : null;
        }
    };
}
Also used : QuickFix(com.intellij.codeInspection.QuickFix) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) XmlUnusedNamespaceInspection(com.intellij.codeInsight.daemon.impl.analysis.XmlUnusedNamespaceInspection) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder) LinkedHashMap(java.util.LinkedHashMap) Project(com.intellij.openapi.project.Project) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with HighlightDisplayKey

use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project intellij-community by JetBrains.

the class HtmlMissingClosingTagInspectionTest method highlightTest.

protected void highlightTest(@Language("HTML") String code) {
    final LocalInspectionTool inspection = getInspection();
    myFixture.enableInspections(inspection);
    final HighlightDisplayKey displayKey = HighlightDisplayKey.find(inspection.getShortName());
    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(HtmlFileType.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

HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)42 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)15 NotNull (org.jetbrains.annotations.NotNull)12 Project (com.intellij.openapi.project.Project)10 PsiElement (com.intellij.psi.PsiElement)10 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)7 Nullable (org.jetbrains.annotations.Nullable)7 InspectionProfile (com.intellij.codeInspection.InspectionProfile)6 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)5 Annotation (com.intellij.lang.annotation.Annotation)4 ArrayList (java.util.ArrayList)4 Issue (com.android.tools.lint.detector.api.Issue)3 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)3 PsiFile (com.intellij.psi.PsiFile)3 NamedScope (com.intellij.psi.search.scope.packageSet.NamedScope)3 Element (org.jdom.Element)3 Issue (com.android.tools.klint.detector.api.Issue)2 SeverityRegistrar (com.intellij.codeInsight.daemon.impl.SeverityRegistrar)2 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)2 QuickFix (com.intellij.codeInspection.QuickFix)2