mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inspection tool window: node exclusion restoration on tree regrouping fixed
This commit is contained in:
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
+55
@@ -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<Class, Set<Object>> myExcludedNodeObjects = new FactoryMap<Class, Set<Object>>() {
|
||||
@Nullable
|
||||
@Override
|
||||
protected Set<Object> create(Class key) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
};
|
||||
|
||||
public boolean isExcluded(InspectionTreeNode node) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
final Set<Object> 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());
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<CommonProblemDescriptor> descriptors = new LinkedHashSet<CommonProblemDescriptor>();
|
||||
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<CommonProblemDescriptor> descriptors){
|
||||
private static void traverseDescriptors(InspectionTreeNode node,
|
||||
LinkedHashSet<CommonProblemDescriptor> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -180,12 +180,12 @@ public class ExportHTMLAction extends AnAction implements DumbAware {
|
||||
final Set<InspectionToolWrapper> toolWrappers = getWorkedTools(toolNode);
|
||||
for (InspectionToolWrapper wrapper : toolWrappers) {
|
||||
InspectionToolPresentation presentation = myView.getGlobalInspectionContext().getPresentation(wrapper);
|
||||
if (!toolNode.isResolved()) {
|
||||
if (!toolNode.isResolved(myView.getExcludedManager())) {
|
||||
final Set<RefEntity> excludedEntities = new HashSet<>();
|
||||
final Set<CommonProblemDescriptor> 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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user