use of com.intellij.codeInspection.QuickFix 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;
}
};
}
Aggregations