From e6d0991620ddc75ea100d428836290d425acdb20 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Fri, 27 Oct 2017 12:02:15 +0300 Subject: [PATCH] inspection view: move tree related methods to InspectionTree --- .../ui/InspectionResultsView.java | 78 +------------------ .../codeInspection/ui/InspectionTree.java | 64 +++++++++++++++ 2 files changed, 66 insertions(+), 76 deletions(-) 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 f6f1de0019d7..af1fd48c016e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInspection.ui; @@ -97,7 +83,6 @@ public class InspectionResultsView extends JPanel implements Disposable, DataPro private static final Key PREVIEW_EDITOR_IS_REUSED_KEY = Key.create("inspection.tool.window.preview.editor.is.reused"); private final InspectionTree myTree; - private final ConcurrentMap> myGroups = ContainerUtil.newConcurrentMap(); private final OccurenceNavigator myOccurenceNavigator; private volatile InspectionProfileImpl myInspectionProfile; private final boolean mySettingsEnabled; @@ -105,7 +90,6 @@ public class InspectionResultsView extends JPanel implements Disposable, DataPro private final AnalysisScope myScope; @NonNls private static final String HELP_ID = "reference.toolWindows.inspections"; - private final ConcurrentMap mySeverityGroupNodes = ContainerUtil.newConcurrentMap(); private final Splitter mySplitter; @NotNull @@ -636,7 +620,7 @@ public class InspectionResultsView extends JPanel implements Disposable, DataPro boolean isSingleInspectionRun) { String groupName = toolWrapper.getGroupDisplayName().isEmpty() ? InspectionProfileEntry.GENERAL_GROUP_NAME : toolWrapper.getGroupDisplayName(); - InspectionTreeNode parentNode = getToolParentNode(groupName, toolWrapper.getGroupPath(), errorLevel, groupedBySeverity, isSingleInspectionRun); + InspectionTreeNode parentNode = myTree.getToolParentNode(groupName, toolWrapper.getGroupPath(), errorLevel, groupedBySeverity, isSingleInspectionRun); InspectionNode toolNode = new InspectionNode(toolWrapper, myInspectionProfile); boolean showStructure = myGlobalInspectionContext.getUIOptions().SHOW_STRUCTURE; toolNode = myProvider.appendToolNodeContent(myGlobalInspectionContext, toolNode, parentNode, showStructure, groupedBySeverity); @@ -707,8 +691,6 @@ public class InspectionResultsView extends JPanel implements Disposable, DataPro try { setUpdating(true); synchronized (myTreeStructureUpdateLock) { - mySeverityGroupNodes.clear(); - myGroups.clear(); myTree.removeAllNodes(); addToolsSynchronously(myGlobalInspectionContext.getTools().values()); } @@ -789,62 +771,6 @@ public class InspectionResultsView extends JPanel implements Disposable, DataPro }); } - - @NotNull - private InspectionTreeNode getToolParentNode(@NotNull String groupName, - @NotNull String[] groupPath, - HighlightDisplayLevel errorLevel, - boolean groupedBySeverity, - boolean isSingleInspectionRun) { - if (!groupedBySeverity && isSingleInspectionRun) { - return getTree().getRoot(); - } - if (groupName.isEmpty()) { - return getRelativeRootNode(groupedBySeverity, errorLevel); - } - ConcurrentMap map = myGroups.get(errorLevel); - if (map == null) { - map = ConcurrencyUtil.cacheOrGet(myGroups, errorLevel, ContainerUtil.newConcurrentMap()); - } - InspectionGroupNode group; - if (groupedBySeverity) { - group = map.get(groupName); - } - else { - group = null; - for (Map groupMap : myGroups.values()) { - if ((group = groupMap.get(groupName)) != null) break; - } - } - if (group == null) { - if (isSingleInspectionRun) { - return getRelativeRootNode(true, errorLevel); - } - group = ConcurrencyUtil.cacheOrGet(map, groupName, new InspectionGroupNode(groupName, groupPath)); - if (!myDisposed) { - getRelativeRootNode(groupedBySeverity, errorLevel).insertByOrder(group, false); - } - } - return group; - } - - @NotNull - private InspectionTreeNode getRelativeRootNode(boolean isGroupedBySeverity, HighlightDisplayLevel level) { - if (isGroupedBySeverity) { - InspectionSeverityGroupNode severityGroupNode = mySeverityGroupNodes.get(level); - if (severityGroupNode == null) { - InspectionSeverityGroupNode newNode = new InspectionSeverityGroupNode(getProject(), level); - severityGroupNode = ConcurrencyUtil.cacheOrGet(mySeverityGroupNodes, level, newNode); - if (severityGroupNode == newNode) { - InspectionTreeNode root = myTree.getRoot(); - root.insertByOrder(severityGroupNode, false); - } - } - return severityGroupNode; - } - return myTree.getRoot(); - } - private OccurenceNavigator getOccurenceNavigator() { return myOccurenceNavigator; } 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 3199863d1306..fdedfd8d1da7 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java @@ -2,6 +2,7 @@ package com.intellij.codeInspection.ui; +import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInspection.CommonProblemDescriptor; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ex.GlobalInspectionContextImpl; @@ -16,6 +17,7 @@ import com.intellij.psi.PsiElement; import com.intellij.ui.TreeSpeedSearch; import com.intellij.ui.treeStructure.Tree; import com.intellij.util.ArrayUtil; +import com.intellij.util.ConcurrencyUtil; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; @@ -30,6 +32,7 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.util.*; +import java.util.concurrent.ConcurrentMap; import static com.intellij.codeInspection.CommonProblemDescriptor.DESCRIPTOR_COMPARATOR; @@ -37,6 +40,9 @@ public class InspectionTree extends Tree { private static final Logger LOG = Logger.getInstance(InspectionTree.class); @NotNull private final GlobalInspectionContextImpl myContext; + @NotNull private final ConcurrentMap mySeverityGroupNodes = ContainerUtil.newConcurrentMap(); + @NotNull private final ConcurrentMap> myGroups = ContainerUtil.newConcurrentMap(); + @NotNull private InspectionTreeState myState = new InspectionTreeState(); private boolean myQueueUpdate; @@ -74,6 +80,8 @@ public class InspectionTree extends Tree { } public void removeAllNodes() { + mySeverityGroupNodes.clear(); + myGroups.clear(); getRoot().removeAllChildren(); ApplicationManager.getApplication().invokeLater(() -> nodeStructureChanged(getRoot())); } @@ -266,6 +274,62 @@ public class InspectionTree extends Tree { return descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]); } + @NotNull + InspectionTreeNode getToolParentNode(@NotNull String groupName, + @NotNull String[] groupPath, + HighlightDisplayLevel errorLevel, + boolean groupedBySeverity, + boolean isSingleInspectionRun) { + if (!groupedBySeverity && isSingleInspectionRun) { + return getRoot(); + } + if (groupName.isEmpty()) { + return getRelativeRootNode(groupedBySeverity, errorLevel); + } + ConcurrentMap map = myGroups.get(errorLevel); + if (map == null) { + map = ConcurrencyUtil.cacheOrGet(myGroups, errorLevel, ContainerUtil.newConcurrentMap()); + } + InspectionGroupNode group; + if (groupedBySeverity) { + group = map.get(groupName); + } + else { + group = null; + for (Map groupMap : myGroups.values()) { + if ((group = groupMap.get(groupName)) != null) break; + } + } + if (group == null) { + if (isSingleInspectionRun) { + return getRelativeRootNode(true, errorLevel); + } + group = ConcurrencyUtil.cacheOrGet(map, groupName, new InspectionGroupNode(groupName, groupPath)); + InspectionResultsView view = myContext.getView(); + if (view != null && !view.isDisposed()) { + getRelativeRootNode(groupedBySeverity, errorLevel).insertByOrder(group, false); + } + } + return group; + } + + @NotNull + private InspectionTreeNode getRelativeRootNode(boolean isGroupedBySeverity, HighlightDisplayLevel level) { + if (isGroupedBySeverity) { + InspectionSeverityGroupNode severityGroupNode = mySeverityGroupNodes.get(level); + if (severityGroupNode == null) { + InspectionSeverityGroupNode newNode = new InspectionSeverityGroupNode(myContext.getProject(), level); + severityGroupNode = ConcurrencyUtil.cacheOrGet(mySeverityGroupNodes, level, newNode); + if (severityGroupNode == newNode) { + InspectionTreeNode root = getRoot(); + root.insertByOrder(severityGroupNode, false); + } + } + return severityGroupNode; + } + return getRoot(); + } + public boolean areDescriptorNodesSelected() { final TreePath[] paths = getSelectionPaths(); if (paths == null) return false;