diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/OfflineIRVTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/OfflineIRVTest.java index d37dbc19a4b1..d07b98d97241 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/OfflineIRVTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/OfflineIRVTest.java @@ -167,11 +167,11 @@ public class OfflineIRVTest extends TestSourceBasedTestCase { + " " + varMessage("a") + "\n"); TreeUtil.selectFirstNode(tree); final InspectionTreeNode root = (InspectionTreeNode)tree.getLastSelectedPathComponent(); - root.ignoreElement(); + root.ignoreElement(myView.getExcludedManager()); TreeUtil.traverse(root, new TreeUtil.Traverse() { @Override public boolean accept(final Object node) { - assertTrue(((InspectionTreeNode)node).isResolved()); + assertTrue(((InspectionTreeNode)node).isResolved(myView.getExcludedManager())); return true; } }); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/ExcludedInspectionTreeNodesManager.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/ExcludedInspectionTreeNodesManager.java new file mode 100644 index 000000000000..a922afc8b408 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/ExcludedInspectionTreeNodesManager.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2016 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. + */ +package com.intellij.codeInspection.ui; + + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.util.containers.FactoryMap; +import org.jetbrains.annotations.Nullable; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @author Dmitry Batkovich + */ +public class ExcludedInspectionTreeNodesManager { + @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + private final Map> myExcludedNodeObjects = new FactoryMap>() { + @Nullable + @Override + protected Set create(Class key) { + return new HashSet<>(); + } + }; + + public boolean isExcluded(InspectionTreeNode node) { + ApplicationManager.getApplication().assertIsDispatchThread(); + final Set excluded = myExcludedNodeObjects.get(node.getClass()); + return excluded.contains(node.getUserObject()); + } + + public void exclude(InspectionTreeNode node) { + ApplicationManager.getApplication().assertIsDispatchThread(); + myExcludedNodeObjects.get(node.getClass()).add(node.getUserObject()); + } + + public void amnesty(InspectionTreeNode node) { + ApplicationManager.getApplication().assertIsDispatchThread(); + myExcludedNodeObjects.get(node.getClass()).remove(node.getUserObject()); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionPackageNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionPackageNode.java index 49ed84396935..45a7d4297178 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionPackageNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionPackageNode.java @@ -37,16 +37,4 @@ public class InspectionPackageNode extends InspectionTreeNode { public Icon getIcon(boolean expanded) { return PlatformIcons.PACKAGE_ICON; } - - @Override - public boolean isResolved() { - System.out.println(""); - return super.isResolved(); - } - - @Override - public void ignoreElement() { - System.out.println("ignore " + this); - super.ignoreElement(); - } } 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 fde5fbaf656e..91adc18cdb96 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -120,6 +120,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren private AnAction myExcludeAction; private EditorEx myPreviewEditor; private InspectionTreeLoadingProgressAware myLoadingProgressPreview; + private final ExcludedInspectionTreeNodesManager myExcludedInspectionTreeNodesManager = new ExcludedInspectionTreeNodesManager(); private final Object myTreeStructureUpdateLock = new Object(); @@ -188,7 +189,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren @Override @Nullable protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) { - if (node instanceof InspectionTreeNode && ((InspectionTreeNode)node).isResolved()) { + if (node instanceof InspectionTreeNode && ((InspectionTreeNode)node).isResolved(myExcludedInspectionTreeNodesManager)) { return null; } if (node instanceof RefElementNode) { @@ -250,7 +251,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren final TreePath[] paths = myTree.getSelectionPaths(); if (paths != null) { for (TreePath path : paths) { - ((InspectionTreeNode)path.getLastPathComponent()).amnesty(); + ((InspectionTreeNode)path.getLastPathComponent()).amnesty(myExcludedInspectionTreeNodesManager); } } myTree.queueUpdate(); @@ -274,7 +275,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren final TreePath[] paths = myTree.getSelectionPaths(); if (paths != null) { for (TreePath path : paths) { - ((InspectionTreeNode)path.getLastPathComponent()).ignoreElement(); + ((InspectionTreeNode)path.getLastPathComponent()).ignoreElement(myExcludedInspectionTreeNodesManager); } } myTree.queueUpdate(); @@ -580,6 +581,11 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren }); } + @NotNull + public ExcludedInspectionTreeNodesManager getExcludedManager() { + return myExcludedInspectionTreeNodesManager; + } + @Nullable public String getCurrentProfileName() { return myInspectionProfile == null ? null : myInspectionProfile.getDisplayName(); 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 1b16c579ce6e..3391ee38e63d 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java @@ -54,6 +54,7 @@ import java.util.*; public class InspectionTree extends Tree { @NotNull private final GlobalInspectionContextImpl myContext; + @NotNull private final ExcludedInspectionTreeNodesManager myExcludedManager; @NotNull private InspectionTreeState myState = new InspectionTreeState(); private boolean myQueueUpdate; @@ -61,6 +62,7 @@ public class InspectionTree extends Tree { @NotNull GlobalInspectionContextImpl context, InspectionResultsView view) { setModel(new DefaultTreeModel(new InspectionRootNode(project, new InspectionTreeUpdater(view)))); myContext = context; + myExcludedManager = view.getExcludedManager(); setCellRenderer(new CellRenderer()); setRootVisible(!myContext.isSingleInspectionRun()); @@ -208,7 +210,7 @@ public class InspectionTree extends Tree { final LinkedHashSet descriptors = new LinkedHashSet(); for (TreePath path : paths) { Object node = path.getLastPathComponent(); - traverseDescriptors((InspectionTreeNode)node, descriptors); + traverseDescriptors((InspectionTreeNode)node, descriptors, myExcludedManager); } return descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]); } @@ -249,9 +251,11 @@ public class InspectionTree extends Tree { return count; } - private static void traverseDescriptors(InspectionTreeNode node, LinkedHashSet descriptors){ + private static void traverseDescriptors(InspectionTreeNode node, + LinkedHashSet descriptors, + ExcludedInspectionTreeNodesManager manager){ if (node instanceof ProblemDescriptionNode) { - if (node.isValid() && !node.isResolved()) { + if (node.isValid() && !node.isResolved(manager)) { final CommonProblemDescriptor descriptor = ((ProblemDescriptionNode)node).getDescriptor(); if (descriptor != null) { descriptors.add(descriptor); @@ -259,7 +263,7 @@ public class InspectionTree extends Tree { } } for(int i = node.getChildCount() - 1; i >= 0; i--){ - traverseDescriptors((InspectionTreeNode)node.getChildAt(i), descriptors); + traverseDescriptors((InspectionTreeNode)node.getChildAt(i), descriptors, manager); } } @@ -316,7 +320,7 @@ public class InspectionTree extends Tree { } } - private static class CellRenderer extends ColoredTreeCellRenderer { + private class CellRenderer extends ColoredTreeCellRenderer { /* private Project myProject; InspectionManagerEx myManager; public CellRenderer(Project project) { @@ -352,14 +356,14 @@ public class InspectionTree extends Tree { append(tail); } - public static SimpleTextAttributes patchAttr(InspectionTreeNode node, SimpleTextAttributes attributes) { - if (node.isResolved()) { + public SimpleTextAttributes patchAttr(InspectionTreeNode node, SimpleTextAttributes attributes) { + if (node.isResolved(myExcludedManager)) { return new SimpleTextAttributes(attributes.getBgColor(), attributes.getFgColor(), attributes.getWaveColor(), attributes.getStyle() | SimpleTextAttributes.STYLE_STRIKEOUT); } return attributes; } - private static SimpleTextAttributes getMainForegroundAttributes(InspectionTreeNode node) { + private SimpleTextAttributes getMainForegroundAttributes(InspectionTreeNode node) { SimpleTextAttributes foreground = SimpleTextAttributes.REGULAR_ATTRIBUTES; if (node instanceof RefElementNode) { RefEntity refElement = ((RefElementNode)node).getElement(); @@ -379,7 +383,7 @@ public class InspectionTree extends Tree { return foreground; } - private static boolean appearsBold(Object node) { + private boolean appearsBold(Object node) { return ((InspectionTreeNode)node).appearsBold(); } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java index 32d4896ae7e8..fbb0d61a4f23 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java @@ -31,9 +31,8 @@ import java.util.Enumeration; * @author max */ public abstract class InspectionTreeNode extends DefaultMutableTreeNode { - private boolean myResolved; protected volatile InspectionTreeUpdater myUpdater; - protected InspectionTreeNode(Object userObject) { + protected InspectionTreeNode (Object userObject) { super(userObject); } @@ -54,8 +53,8 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode { return true; } - public boolean isResolved(){ - return myResolved; + public boolean isResolved(ExcludedInspectionTreeNodesManager excludedManager){ + return excludedManager.isExcluded(this); } public boolean appearsBold() { @@ -66,21 +65,21 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode { return FileStatus.NOT_CHANGED; } - public void ignoreElement() { - myResolved = true; + public void ignoreElement(ExcludedInspectionTreeNodesManager excludedManager) { + excludedManager.exclude(this); Enumeration enumeration = children(); while (enumeration.hasMoreElements()) { InspectionTreeNode child = (InspectionTreeNode)enumeration.nextElement(); - child.ignoreElement(); + child.ignoreElement(excludedManager); } } - public void amnesty() { - myResolved = false; + public void amnesty(ExcludedInspectionTreeNodesManager excludedManager) { + excludedManager.amnesty(this); Enumeration enumeration = children(); while (enumeration.hasMoreElements()) { InspectionTreeNode child = (InspectionTreeNode)enumeration.nextElement(); - child.amnesty(); + child.amnesty(excludedManager); } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java index 1e559f476fb4..d2b4afe81260 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java @@ -91,18 +91,18 @@ public class ProblemDescriptionNode extends InspectionTreeNode { @Override - public boolean isResolved() { + public boolean isResolved(ExcludedInspectionTreeNodesManager manager) { return myElement instanceof RefElement && getPresentation().isProblemResolved(myElement, getDescriptor()); } @Override - public void ignoreElement() { + public void ignoreElement(ExcludedInspectionTreeNodesManager manager) { InspectionToolPresentation presentation = getPresentation(); presentation.ignoreCurrentElementProblem(getElement(), getDescriptor()); } @Override - public void amnesty() { + public void amnesty(ExcludedInspectionTreeNodesManager manager) { InspectionToolPresentation presentation = getPresentation(); presentation.amnesty(getElement()); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java index f984004c2e21..c2e07ca0cdb2 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java @@ -83,21 +83,20 @@ public class RefElementNode extends InspectionTreeNode { } @Override - public boolean isResolved() { + public boolean isResolved(ExcludedInspectionTreeNodesManager excludedManager) { return myToolPresentation.isElementIgnored(getElement()); } - @Override - public void ignoreElement() { + public void ignoreElement(ExcludedInspectionTreeNodesManager excludedManager) { myToolPresentation.ignoreCurrentElement(getElement()); - super.ignoreElement(); + super.ignoreElement(excludedManager); } @Override - public void amnesty() { + public void amnesty(ExcludedInspectionTreeNodesManager excludedManager) { myToolPresentation.amnesty(getElement()); - super.amnesty(); + super.amnesty(excludedManager); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/ExportHTMLAction.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/ExportHTMLAction.java index e285b1124d95..d914e961233b 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/ExportHTMLAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/ExportHTMLAction.java @@ -180,12 +180,12 @@ public class ExportHTMLAction extends AnAction implements DumbAware { final Set toolWrappers = getWorkedTools(toolNode); for (InspectionToolWrapper wrapper : toolWrappers) { InspectionToolPresentation presentation = myView.getGlobalInspectionContext().getPresentation(wrapper); - if (!toolNode.isResolved()) { + if (!toolNode.isResolved(myView.getExcludedManager())) { final Set excludedEntities = new HashSet<>(); final Set excludedDescriptors = new HashSet<>(); TreeUtil.traverse(toolNode, o -> { InspectionTreeNode n = (InspectionTreeNode)o; - if (n.isResolved()) { + if (n.isResolved(myView.getExcludedManager())) { if (n instanceof RefElementNode) { excludedEntities.add(((RefElementNode)n).getElement()); }