From fe9fb1aef75c20ca656a80913a278f85e3056717 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Thu, 10 Mar 2016 18:03:14 +0300 Subject: [PATCH] inspection tool window: do not display useless nodes (inspection group, root) on run single inspection --- .../actions/RunInspectionIntention.java | 1 + .../ex/GlobalInspectionContextImpl.java | 9 +++++++++ .../ui/DefaultInspectionToolPresentation.java | 2 +- .../ui/InspectionResultsView.java | 19 +++++++++++++++---- .../codeInspection/ui/InspectionTree.java | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java index b3837b2b47cb..e4411fdc219f 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java @@ -134,6 +134,7 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi model.setEditable(toolWrapper.getDisplayName()); final GlobalInspectionContextImpl inspectionContext = managerEx.createNewGlobalContext(false); inspectionContext.setExternalProfile(model); + inspectionContext.setSingleInspectionRun(true); return inspectionContext; } 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 bdcf9faba876..e46a683aa3db 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -94,6 +94,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp private volatile InspectionResultsView myView; private Content myContent; private volatile boolean myViewClosed = true; + private volatile boolean mySingleInspectionRun; @NotNull private AnalysisUIOptions myUIOptions; @@ -988,4 +989,12 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp public boolean isViewClosed() { return myViewClosed; } + + public void setSingleInspectionRun(boolean singleInspectionRun) { + mySingleInspectionRun = singleInspectionRun; + } + + public boolean isSingleInspectionRun() { + return mySingleInspectionRun; + } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java index 91a447042951..9df9c5f6d6a8 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/DefaultInspectionToolPresentation.java @@ -247,7 +247,7 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro final InspectionNode toolNode; toolNode = myToolNode == null ? view.addTool(myToolWrapper, HighlightDisplayLevel.find(getSeverity((RefElement)refElement)), - context.getUIOptions().GROUP_BY_SEVERITY) : myToolNode; + context.getUIOptions().GROUP_BY_SEVERITY, context.isSingleInspectionRun()) : myToolNode; final Map problems = new HashMap(); problems.put(refElement, descriptors); 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 f29ea68ee74c..c789ae0765d5 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -552,10 +552,11 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren @NotNull public InspectionNode addTool(@NotNull final InspectionToolWrapper toolWrapper, HighlightDisplayLevel errorLevel, - boolean groupedBySeverity) { + boolean groupedBySeverity, + boolean isSingleInspectionRun) { String groupName = toolWrapper.getGroupDisplayName().isEmpty() ? InspectionProfileEntry.GENERAL_GROUP_NAME : toolWrapper.getGroupDisplayName(); - InspectionTreeNode parentNode = getToolParentNode(groupName, errorLevel, groupedBySeverity); + InspectionTreeNode parentNode = getToolParentNode(groupName, errorLevel, groupedBySeverity, isSingleInspectionRun); InspectionNode toolNode = new InspectionNode(toolWrapper); boolean showStructure = myGlobalInspectionContext.getUIOptions().SHOW_STRUCTURE; myProvider.appendToolNodeContent(myGlobalInspectionContext, toolNode, parentNode, showStructure); @@ -628,6 +629,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren setUpdating(true); InspectionProfile profile = myInspectionProfile; boolean isGroupedBySeverity = myGlobalInspectionContext.getUIOptions().GROUP_BY_SEVERITY; + boolean singleInspectionRun = myGlobalInspectionContext.isSingleInspectionRun(); myGroups.clear(); final Map tools = myGlobalInspectionContext.getTools(); for (Tools currentTools : tools.values()) { @@ -637,7 +639,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren InspectionToolWrapper toolWrapper = state.getTool(); if (myProvider.checkReportedProblems(myGlobalInspectionContext, toolWrapper)) { addTool(toolWrapper, ((InspectionProfileImpl)profile).getErrorLevel(key, state.getScope(myProject), myProject), - isGroupedBySeverity); + isGroupedBySeverity, singleInspectionRun); } } } @@ -657,7 +659,13 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren } @NotNull - private InspectionTreeNode getToolParentNode(@NotNull String groupName, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) { + private InspectionTreeNode getToolParentNode(@NotNull String groupName, + HighlightDisplayLevel errorLevel, + boolean groupedBySeverity, + boolean isSingleInspectionRun) { + if (!groupedBySeverity && isSingleInspectionRun) { + return getTree().getRoot(); + } if (groupName.isEmpty()) { return getRelativeRootNode(groupedBySeverity, errorLevel); } @@ -676,6 +684,9 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren } } if (group == null) { + if (isSingleInspectionRun) { + return getRelativeRootNode(true, errorLevel); + } group = ConcurrencyUtil.cacheOrGet(map, groupName, new InspectionGroupNode(groupName)); if (!myDisposed) { insertByIndex(group, getRelativeRootNode(groupedBySeverity, errorLevel)); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java index a9807900b53c..7880483f503f 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java @@ -63,6 +63,7 @@ public class InspectionTree extends Tree { myContext = context; setCellRenderer(new CellRenderer()); + setRootVisible(!myContext.isSingleInspectionRun()); setShowsRootHandles(true); UIUtil.setLineStyleAngled(this); addTreeWillExpandListener(new ExpandListener());