diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java index 94c0fc425da8..ed7445199c3c 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/DummyEntryPointsTool.java @@ -47,7 +47,9 @@ public class DummyEntryPointsTool extends FilteringInspectionTool { public void runInspection(@NotNull AnalysisScope scope, @NotNull final InspectionManager manager) {} - public void exportResults(@NotNull Element parentNode) {} + @Override + public void exportResults(@NotNull Element parentNode, RefEntity refEntity) { + } @NotNull public JobDescriptor[] getJobDescriptors(GlobalInspectionContext globalInspectionContext) { diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java index d3ffbc9bb33b..6968e8ff5f9f 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java @@ -631,45 +631,43 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool { return myComposer; } - public void exportResults(@NotNull final Element parentNode) { + @Override + public void exportResults(@NotNull final Element parentNode, RefEntity refEntity) { + if (!(refEntity instanceof RefJavaElement)) return; final WeakUnreferencedFilter filter = new WeakUnreferencedFilter(this); - getRefManager().iterate(new RefJavaVisitor() { - @Override public void visitElement(RefEntity refEntity) { - if (!(refEntity instanceof RefJavaElement)) return; - if (!getIgnoredRefElements().contains(refEntity) && filter.accepts((RefJavaElement)refEntity)) { - if (refEntity instanceof RefImplicitConstructor) refEntity = ((RefImplicitConstructor)refEntity).getOwnerClass(); - Element element = refEntity.getRefManager().export(refEntity, parentNode, -1); - @NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag")); + if (!getIgnoredRefElements().contains(refEntity) && filter.accepts((RefJavaElement)refEntity)) { + if (refEntity instanceof RefImplicitConstructor) refEntity = ((RefImplicitConstructor)refEntity).getOwnerClass(); + Element element = refEntity.getRefManager().export(refEntity, parentNode, -1); + @NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag")); - if (refEntity instanceof RefElement) { - final RefElement refElement = (RefElement)refEntity; - final HighlightSeverity severity = getCurrentSeverity(refElement); - final String attributeKey = getTextAttributeKey(refElement.getElement().getProject(), severity, ProblemHighlightType.LIKE_UNUSED_SYMBOL); - problemClassElement.setAttribute("severity", severity.myName); - problemClassElement.setAttribute("attribute_key", attributeKey); - } - - problemClassElement.addContent(InspectionsBundle.message("inspection.export.results.dead.code")); - element.addContent(problemClassElement); - - @NonNls Element hintsElement = new Element("hints"); - - for (String hint : HINTS) { - @NonNls Element hintElement = new Element("hint"); - hintElement.setAttribute("value", hint); - hintsElement.addContent(hintElement); - } - element.addContent(hintsElement); - - - Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag")); - StringBuffer buf = new StringBuffer(); - DeadHTMLComposer.appendProblemSynopsis((RefElement)refEntity, buf); - descriptionElement.addContent(buf.toString()); - element.addContent(descriptionElement); - } + if (refEntity instanceof RefElement) { + final RefElement refElement = (RefElement)refEntity; + final HighlightSeverity severity = getCurrentSeverity(refElement); + final String attributeKey = + getTextAttributeKey(refElement.getElement().getProject(), severity, ProblemHighlightType.LIKE_UNUSED_SYMBOL); + problemClassElement.setAttribute("severity", severity.myName); + problemClassElement.setAttribute("attribute_key", attributeKey); } - }); + + problemClassElement.addContent(InspectionsBundle.message("inspection.export.results.dead.code")); + element.addContent(problemClassElement); + + @NonNls Element hintsElement = new Element("hints"); + + for (String hint : HINTS) { + @NonNls Element hintElement = new Element("hint"); + hintElement.setAttribute("value", hint); + hintsElement.addContent(hintElement); + } + element.addContent(hintsElement); + + + Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag")); + StringBuffer buf = new StringBuffer(); + DeadHTMLComposer.appendProblemSynopsis((RefElement)refEntity, buf); + descriptionElement.addContent(buf.toString()); + element.addContent(descriptionElement); + } } public QuickFixAction[] getQuickFixes(final RefEntity[] refElements) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/CommonInspectionToolWrapper.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/CommonInspectionToolWrapper.java index 3858734b488c..60013c809bf1 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/CommonInspectionToolWrapper.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/CommonInspectionToolWrapper.java @@ -20,6 +20,7 @@ import com.intellij.codeInspection.GlobalInspectionContext; import com.intellij.codeInspection.InspectionEP; import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.reference.RefEntity; +import com.intellij.codeInspection.reference.RefVisitor; import com.intellij.codeInspection.ui.InspectionNode; import com.intellij.codeInspection.ui.InspectionTreeNode; import org.jdom.Element; @@ -111,7 +112,7 @@ public class CommonInspectionToolWrapper extends InspectionToolWrapper\n"); } for (Object o : list) { @@ -263,19 +262,16 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem return myComposer; } - public void exportResults(@NotNull final Element parentNode) { - getRefManager().iterate(new RefVisitor() { - @Override public void visitElement(final RefEntity refEntity) { - synchronized (lock) { - if (getProblemElements().containsKey(refEntity)) { - CommonProblemDescriptor[] descriptions = getDescriptions(refEntity); - if (descriptions != null) { - exportResults(descriptions, refEntity, parentNode); - } - } + @Override + public void exportResults(final @NotNull Element parentNode, RefEntity refEntity) { + synchronized (lock) { + if (getProblemElements().containsKey(refEntity)) { + CommonProblemDescriptor[] descriptions = getDescriptions(refEntity); + if (descriptions != null) { + exportResults(descriptions, refEntity, parentNode); } } - }); + } } private void exportResults(@NotNull final CommonProblemDescriptor[] descriptions, final RefEntity refEntity, final Element parentNode) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index 872844b78bbf..18d9ef0bc84e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -105,6 +105,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G private final Map myTools = new THashMap(); private AnalysisUIOptions myUIOptions; + @NonNls static final String LOCAL_TOOL_ATTRIBUTE = "is_local_tool"; public GlobalInspectionContextImpl(Project project, NotNullLazyValue contentManager) { myProject = project; @@ -296,44 +297,63 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G public void run() { performInspectionsWithProgress(scope, manager); @NonNls final String ext = ".xml"; + final Map globalTools = new HashMap(); for (Map.Entry stringSetEntry : myTools.entrySet()) { - final Element root = new Element(InspectionsBundle.message("inspection.problems")); - final Document doc = new Document(root); final Tools sameTools = stringSetEntry.getValue(); boolean hasProblems = false; - boolean isLocalTool = false; String toolName = stringSetEntry.getKey(); if (sameTools != null) { for (ScopeToolState toolDescr : sameTools.getTools()) { final InspectionTool tool = (InspectionTool)toolDescr.getTool(); if (tool instanceof LocalInspectionToolWrapper) { hasProblems = new File(outputPath, toolName + ext).exists(); - isLocalTool = true; } else { tool.updateContent(); if (tool.hasReportedProblems()) { - hasProblems = true; - tool.exportResults(root); + final Element root = new Element(InspectionsBundle.message("inspection.problems")); + globalTools.put(root, sameTools); + LOG.assertTrue(!hasProblems, toolName); + break; } } } } if (!hasProblems) continue; - @NonNls final String isLocalToolAttribute = "is_local_tool"; - root.setAttribute(isLocalToolAttribute, String.valueOf(isLocalTool)); try { new File(outputPath).mkdirs(); final File file = new File(outputPath, toolName + ext); inspectionsResults.add(file); - if (isLocalTool) { - FileUtil.writeToFile(file, ("").getBytes("UTF-8"), true); - } - else { - PathMacroManager.getInstance(getProject()).collapsePaths(doc.getRootElement()); - JDOMUtil.writeDocument(doc, file, "\n"); + FileUtil.writeToFile(file, ("").getBytes("UTF-8"), true); + } + catch (IOException e) { + LOG.error(e); + } + } + + getRefManager().iterate(new RefVisitor() { + @Override + public void visitElement(final RefEntity refEntity) { + for (Element element : globalTools.keySet()) { + final Tools tools = globalTools.get(element); + for (ScopeToolState state : tools.getTools()) { + ((InspectionTool)state.getTool()).exportResults(element, refEntity); + } } } + }); + + for (Element element : globalTools.keySet()) { + final String toolName = globalTools.get(element).getShortName(); + element.setAttribute(LOCAL_TOOL_ATTRIBUTE, Boolean.toString(false)); + final Document doc = new Document(element); + PathMacroManager.getInstance(getProject()).collapsePaths(doc.getRootElement()); + try { + new File(outputPath).mkdirs(); + final File file = new File(outputPath, toolName + ext); + inspectionsResults.add(file); + JDOMUtil.writeDocument(doc, file, "\n"); + } catch (IOException e) { LOG.error(e); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java index 279ef0b60f33..e9d0aa00349d 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java @@ -29,10 +29,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfoType; import com.intellij.codeInsight.daemon.impl.SeverityRegistrar; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.*; -import com.intellij.codeInspection.reference.RefElement; -import com.intellij.codeInspection.reference.RefEntity; -import com.intellij.codeInspection.reference.RefManager; -import com.intellij.codeInspection.reference.RefModule; +import com.intellij.codeInspection.reference.*; import com.intellij.codeInspection.ui.InspectionNode; import com.intellij.codeInspection.ui.InspectionTreeNode; import com.intellij.lang.annotation.HighlightSeverity; @@ -69,7 +66,16 @@ public abstract class InspectionTool extends InspectionProfileEntry { public abstract void runInspection(@NotNull AnalysisScope scope, @NotNull InspectionManager manager); - public abstract void exportResults(@NotNull Element parentNode); + public void exportResults(@NotNull final Element parentNode) { + getRefManager().iterate(new RefVisitor(){ + @Override + public void visitElement(RefEntity elem) { + exportResults(parentNode, elem); + } + }); + } + + public abstract void exportResults(@NotNull Element parentNode, RefEntity refEntity); public abstract boolean isGraphNeeded(); @Nullable