From 9a34cd0ae9f6caafd822c132638fd1ae511628af Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 8 Jul 2011 20:22:10 +0400 Subject: [PATCH] batch inspections: append local problems during progress --- .../source/tree/JavaChangeUtilSupport.java | 7 +--- .../ex/GlobalInspectionContextImpl.java | 33 ++++++++------- .../ex/InspectionRVContentProvider.java | 15 ++++++- .../ex/InspectionRVContentProviderImpl.java | 11 ++--- .../codeInspection/ex/InspectionTool.java | 7 ++-- .../ex/LocalInspectionToolWrapper.java | 42 +++++++++++++++++-- .../OfflineInspectionRVContentProvider.java | 6 ++- .../ui/InspectionResultsView.java | 7 +++- 8 files changed, 94 insertions(+), 34 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaChangeUtilSupport.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaChangeUtilSupport.java index f73cd6bb916a..0c0019c2023c 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaChangeUtilSupport.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaChangeUtilSupport.java @@ -177,7 +177,7 @@ public class JavaChangeUtilSupport implements TreeGenerator, TreeCopyHandler { element.rawAddChildren(keyword); return element; } - if (type instanceof PsiWildcardType) { + if (type instanceof PsiWildcardType || type instanceof PsiCapturedWildcardType || type instanceof PsiDisjunctionType) { final String originalText = original.getText(); return createType(original.getProject(), originalText, null, generated); } @@ -185,10 +185,7 @@ public class JavaChangeUtilSupport implements TreeGenerator, TreeCopyHandler { LightTypeElement te = new LightTypeElement(original.getManager(), ((PsiIntersectionType)type).getRepresentative()); return ChangeUtil.generateTreeElement(te, table, manager); } - if (type instanceof PsiDisjunctionType) { - final String originalText = original.getText(); - return createType(original.getProject(), originalText, null, generated); - } + PsiClassType classType = (PsiClassType)type; String text = classType.getPresentableText(); 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 2b91b7b47e7c..936c1fd3ddb5 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -184,7 +184,8 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G } - public void addView(InspectionResultsView view, String title) { + public synchronized void addView(InspectionResultsView view, String title) { + if (myContent != null) return; myContentManager.getValue().addContentManagerListener(new ContentManagerAdapter() { public void contentRemoved(ContentManagerEvent event) { if (event.getContent() == myContent){ @@ -207,7 +208,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.INSPECTION).activate(null); } - private void addView(InspectionResultsView view) { + protected void addView(InspectionResultsView view) { addView(view, view.getCurrentProfileName() == null ? InspectionsBundle.message("inspection.results.title") : InspectionsBundle.message("inspection.results.for.profile.toolwindow.title", view.getCurrentProfileName())); @@ -368,6 +369,10 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G } } + public InspectionResultsView getView() { + return myView; + } + private static void ignoreElementRecursively(final InspectionTool tool, final RefEntity refElement) { if (refElement != null) { tool.ignoreCurrentElement(refElement); @@ -397,8 +402,9 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G PsiDocumentManager.getInstance(myProject).commitAllDocuments(); LOG.info("Code inspection started"); - - ProgressManager.getInstance().run(new Task.Backgroundable(getProject(), InspectionsBundle.message("inspection.progress.title"), true, new PerformAnalysisInBackgroundOption(myProject)) { + myView = new InspectionResultsView(myProject, getCurrentProfile(), scope, this, new InspectionRVContentProviderImpl(myProject)); + ProgressManager.getInstance().run(new Task.Backgroundable(getProject(), InspectionsBundle.message("inspection.progress.title"), true, + new PerformAnalysisInBackgroundOption(myProject)) { public void run(@NotNull ProgressIndicator indicator) { performInspectionsWithProgress(scope, manager); } @@ -409,16 +415,15 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G public void run() { LOG.info("Code inspection finished"); - InspectionResultsView view = new InspectionResultsView(myProject, getCurrentProfile(), - scope, GlobalInspectionContextImpl.this, - new InspectionRVContentProviderImpl(myProject)); - if (!view.update() && !getUIOptions().SHOW_ONLY_DIFF) { - Messages.showMessageDialog(myProject, InspectionsBundle.message("inspection.no.problems.message"), - InspectionsBundle.message("inspection.no.problems.dialog.title"), Messages.getInformationIcon()); - close(true); - } - else { - addView(view); + if (myView != null) { + if (!myView.update() && !getUIOptions().SHOW_ONLY_DIFF) { + Messages.showMessageDialog(myProject, InspectionsBundle.message("inspection.no.problems.message"), + InspectionsBundle.message("inspection.no.problems.dialog.title"), Messages.getInformationIcon()); + close(true); + } + else { + addView(myView); + } } } }); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionRVContentProvider.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionRVContentProvider.java index 99ce560feec2..5b85ae218279 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionRVContentProvider.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionRVContentProvider.java @@ -20,6 +20,8 @@ */ package com.intellij.codeInspection.ex; +import com.intellij.codeInspection.CommonProblemDescriptor; +import com.intellij.codeInspection.reference.RefEntity; import com.intellij.codeInspection.ui.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; @@ -65,9 +67,20 @@ public abstract class InspectionRVContentProvider { public abstract QuickFixAction[] getQuickFixes(final InspectionTool tool, final InspectionTree tree); + public void appendToolNodeContent(final InspectionNode toolNode, + final InspectionTreeNode parentNode, + final boolean showStructure) { + final InspectionTool tool = toolNode.getTool(); + final Map> content = tool.getContent(); + appendToolNodeContent(toolNode, parentNode, showStructure, content != null ? content : new HashMap>(), + tool instanceof DescriptorProviderInspection ? ((DescriptorProviderInspection)tool).getProblemElements() : null); + } + public abstract void appendToolNodeContent(final InspectionNode toolNode, final InspectionTreeNode parentNode, - final boolean showStructure); + final boolean showStructure, + final Map> contents, + final Map problems); protected abstract void appendDescriptor(final InspectionTool tool, final UserObjectContainer container, diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionRVContentProviderImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionRVContentProviderImpl.java index 01576c00b322..d668822d15d5 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionRVContentProviderImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionRVContentProviderImpl.java @@ -54,19 +54,20 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider return refEntities.length == 0 ? null : tool.getQuickFixes(refEntities); } - public void appendToolNodeContent(final InspectionNode toolNode, final InspectionTreeNode parentNode, final boolean showStructure) { + + public void appendToolNodeContent(final InspectionNode toolNode, + final InspectionTreeNode parentNode, + final boolean showStructure, + final Map> contents, + final Map problems) { final InspectionTool tool = toolNode.getTool(); - - final Map problems = - tool instanceof DescriptorProviderInspection ? ((DescriptorProviderInspection)tool).getProblemElements() : null; Function> computeContainer = new Function>() { public UserObjectContainer fun(final RefEntity refElement) { return new RefElementContainer(refElement, problems != null ? problems.get(refElement) : null); } }; - final Map> contents = tool.getContent(); final Set moduleProblems = tool.getModuleProblems(); if (moduleProblems != null && !moduleProblems.isEmpty()) { Set entities = contents.get(""); 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 fa8cc41e8a80..9733185e63c3 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java @@ -52,6 +52,7 @@ import java.util.Set; public abstract class InspectionTool extends InspectionProfileEntry { private GlobalInspectionContextImpl myContext; protected static String ourOutputPath; + protected InspectionNode myToolNode; public void initialize(@NotNull GlobalInspectionContextImpl context) { myContext = context; @@ -205,9 +206,9 @@ public abstract class InspectionTool extends InspectionProfileEntry { } public InspectionNode createToolNode(final InspectionRVContentProvider provider, final InspectionTreeNode parentNode, final boolean showStructure) { - final InspectionNode toolNode = new InspectionNode(this); - provider.appendToolNodeContent(toolNode, parentNode, showStructure); - return toolNode; + myToolNode = new InspectionNode(this); + provider.appendToolNodeContent(myToolNode, parentNode, showStructure); + return myToolNode; } @Nullable diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/LocalInspectionToolWrapper.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/LocalInspectionToolWrapper.java index 051a9bf7074c..f13634d95ff3 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/LocalInspectionToolWrapper.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/LocalInspectionToolWrapper.java @@ -20,7 +20,11 @@ import com.intellij.analysis.AnalysisScope; import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInspection.*; import com.intellij.codeInspection.reference.RefElement; +import com.intellij.codeInspection.reference.RefEntity; import com.intellij.codeInspection.reference.RefManagerImpl; +import com.intellij.codeInspection.ui.InspectionResultsView; +import com.intellij.codeInspection.ui.InspectionTreeNode; +import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -28,15 +32,16 @@ import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.*; import com.intellij.util.TripleFunction; +import com.intellij.util.containers.*; +import com.intellij.util.containers.HashSet; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.util.ArrayList; +import javax.swing.tree.DefaultTreeModel; +import java.util.*; import java.util.HashMap; -import java.util.List; -import java.util.Map; /** * @author max @@ -100,6 +105,37 @@ public final class LocalInspectionToolWrapper extends DescriptorProviderInspecti } }; + @Override + protected void addProblemElement(RefEntity refElement, boolean filterSuppressed, CommonProblemDescriptor... descriptions) { + super.addProblemElement(refElement, filterSuppressed, descriptions); + final InspectionResultsView view = getContext().getView(); + if (view != null && refElement instanceof RefElement) { + if (myToolNode == null) { + final HighlightSeverity currentSeverity = getCurrentSeverity((RefElement)refElement); + view.addTool(this, HighlightDisplayLevel.find(currentSeverity), getContext().getUIOptions().GROUP_BY_SEVERITY); + } + final HashMap problems = new HashMap(); + problems.put(refElement, descriptions); + final HashMap> contents = new HashMap>(); + final String groupName = refElement.getRefManager().getGroupName((RefElement)refElement); + Set content = contents.get(groupName); + if (content == null) { + content = new HashSet(); + contents.put(groupName, content); + } + content.add(refElement); + view.getProvider().appendToolNodeContent(myToolNode, + (InspectionTreeNode)myToolNode.getParent(), getContext().getUIOptions().SHOW_STRUCTURE, + contents, problems); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + getContext().addView(view); + ((DefaultTreeModel)view.getTree().getModel()).reload(myToolNode); + } + }); + } + } + public static void addProblemDescriptors(List descriptors, boolean filterSuppressed, @NotNull GlobalInspectionContextImpl context, diff --git a/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineInspectionRVContentProvider.java b/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineInspectionRVContentProvider.java index 87c0cdf61fe0..5c0d0bd3a8bd 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineInspectionRVContentProvider.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineInspectionRVContentProvider.java @@ -106,7 +106,11 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi return false; } - public void appendToolNodeContent(final InspectionNode toolNode, final InspectionTreeNode parentNode, final boolean showStructure) { + public void appendToolNodeContent(final InspectionNode toolNode, + final InspectionTreeNode parentNode, + final boolean showStructure, + final Map> contents, + final Map problems) { final InspectionTool tool = toolNode.getTool(); final Map> filteredContent = getFilteredContent(tool); if (filteredContent != null && !filteredContent.values().isEmpty()) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java index e8755c2f07b4..5209ee3f33b1 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -425,7 +425,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren setCursor(currentCursor); } - private void addTool(InspectionTool tool, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) { + public void addTool(InspectionTool tool, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) { final InspectionTreeNode parentNode = getToolParentNode(tool.getGroupDisplayName().length() > 0 ? tool.getGroupDisplayName() : InspectionProfileEntry.GENERAL_GROUP_NAME, errorLevel, groupedBySeverity); tool.createToolNode(myProvider, parentNode, myGlobalInspectionContext.getUIOptions().SHOW_STRUCTURE); registerActionShortcuts(tool); @@ -492,10 +492,13 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren return resultsFound; } - private InspectionTreeNode getToolParentNode(String groupName, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) { + public InspectionTreeNode getToolParentNode(String groupName, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) { if (groupName == null || groupName.length() == 0) { return getRelativeRootNode(groupedBySeverity, errorLevel); } + if (myGroups == null) { + myGroups = new HashMap>(); + } Map map = myGroups.get(errorLevel); if (map == null) { map = new HashMap();