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;
}
};
}
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();
}
Aggregations