import com.intellij.codeInspection.reference.RefEntity;
import com.intellij.codeInspection.reference.RefManagerImpl;
import com.intellij.codeInspection.reference.RefVisitor;
-import com.intellij.codeInspection.ui.*;
+import com.intellij.codeInspection.ui.DefaultInspectionToolPresentation;
+import com.intellij.codeInspection.ui.InspectionResultsView;
+import com.intellij.codeInspection.ui.InspectionToolPresentation;
+import com.intellij.codeInspection.ui.InspectionTreeState;
import com.intellij.concurrency.JobLauncher;
import com.intellij.concurrency.JobLauncherImpl;
import com.intellij.concurrency.SensitiveProgressWrapper;
@NotNull
private AnalysisUIOptions myUIOptions;
- private ExpansionTreeState<InspectionTreeNode> myTreeState;
+ private InspectionTreeState myTreeState;
public GlobalInspectionContextImpl(@NotNull Project project, @NotNull NotNullLazyValue<ContentManager> contentManager) {
super(project);
return myContentManager.getValue();
}
- public void setTreeState(ExpansionTreeState<InspectionTreeNode> treeState) {
+ public void setTreeState(InspectionTreeState treeState) {
myTreeState = treeState;
}
}
private void inspectFile(@NotNull final PsiFile file,
- @NotNull final TextRange range,
- @NotNull final InspectionManager inspectionManager,
- @NotNull List<Tools> localTools,
- @NotNull List<Tools> globalSimpleTools,
- @NotNull final Map<String, InspectionToolWrapper> wrappersMap) {
+ @NotNull final TextRange range,
+ @NotNull final InspectionManager inspectionManager,
+ @NotNull List<Tools> localTools,
+ @NotNull List<Tools> globalSimpleTools,
+ @NotNull final Map<String, InspectionToolWrapper> wrappersMap) {
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
if (document == null) return;
}, ModalityState.defaultModalityState());
return;
}
-
+
Runnable runnable = () -> {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(files)) return;
CleanupInspectionIntention.applyFixesNoSort(getProject(), "Code Cleanup", descriptors, null);
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import javax.swing.event.TreeExpansionEvent;
+import javax.swing.event.TreeWillExpandListener;
import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.ExpandVetoException;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.util.*;
@NotNull private final GlobalInspectionContextImpl myContext;
@NotNull private final ExcludedInspectionTreeNodesManager myExcludedManager;
- @NotNull private ExpansionTreeState<InspectionTreeNode> myState = new ExpansionTreeState<>(InspectionResultsViewComparator.getInstance());
+ @NotNull private InspectionTreeState myState = new InspectionTreeState();
private boolean myQueueUpdate;
public InspectionTree(@NotNull GlobalInspectionContextImpl context,
setRootVisible(false);
setShowsRootHandles(true);
UIUtil.setLineStyleAngled(this);
- addTreeWillExpandListener(new TreeWillExpandListenerImpl(myState));
+ addTreeWillExpandListener(new ExpandListener());
myState.getExpandedUserObjects().add(project);
myState.restoreExpansionAndSelection(this, treeNodesMightChange);
}
- public ExpansionTreeState<InspectionTreeNode> getTreeState() {
+ public void setState(@NotNull InspectionTreeState state) {
+ myState = state;
+ }
+
+ public InspectionTreeState getTreeState() {
return myState;
}
- public void setTreeState(@NotNull ExpansionTreeState<InspectionTreeNode> treeState) {
+ public void setTreeState(@NotNull InspectionTreeState treeState) {
myState = treeState;
}
+ private class ExpandListener implements TreeWillExpandListener {
+ @Override
+ public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
+ final InspectionTreeNode node = (InspectionTreeNode)event.getPath().getLastPathComponent();
+ myState.getExpandedUserObjects().add(node.getUserObject());
+ }
+
+ @Override
+ public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
+ InspectionTreeNode node = (InspectionTreeNode)event.getPath().getLastPathComponent();
+ myState.getExpandedUserObjects().remove(node.getUserObject());
+ }
+ }
+
@NotNull
public GlobalInspectionContextImpl getContext() {
return myContext;
package com.intellij.codeInspection.ui;
import com.intellij.util.ui.tree.TreeUtil;
-import org.jetbrains.annotations.NotNull;
-import javax.swing.*;
-import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
/**
* @author Dmitry Batkovich
*/
-@SuppressWarnings("unchecked")
-public class ExpansionTreeState<T extends DefaultMutableTreeNode> {
- private final Set<Object> myExpandedUserObjects;
- @NotNull
- private final Comparator<T> myComparator;
- private TreeSelectionPath mySelectionPath;
-
- public ExpansionTreeState(@NotNull Comparator<T> comparator) {
- myExpandedUserObjects = new HashSet<>();
- myComparator = comparator;
- }
+public class InspectionTreeState {
+ private final Set<Object> myExpandedUserObjects = new HashSet<>();
+ private InspectionTreeSelectionPath mySelectionPath;
public Set<Object> getExpandedUserObjects() {
return myExpandedUserObjects;
}
public void setSelectionPath(TreePath selectionPath) {
- mySelectionPath = new TreeSelectionPath(selectionPath);
+ mySelectionPath = new InspectionTreeSelectionPath(selectionPath);
}
- public void restoreExpansionAndSelection(JTree tree, boolean treeNodeMightChange) {
- restoreExpansionStatus((T)tree.getModel().getRoot(), tree);
+ public void restoreExpansionAndSelection(InspectionTree tree, boolean treeNodeMightChange) {
+ restoreExpansionStatus((InspectionTreeNode)tree.getModel().getRoot(), tree);
if (mySelectionPath != null) {
mySelectionPath.restore(tree, treeNodeMightChange);
} else {
}
}
- private void restoreExpansionStatus(T node, JTree tree) {
+ private void restoreExpansionStatus(InspectionTreeNode node, InspectionTree tree) {
if (getExpandedUserObjects().contains(node.getUserObject())) {
//sortChildren(node);
TreeNode[] pathToNode = node.getPath();
tree.expandPath(new TreePath(pathToNode));
Enumeration children = node.children();
while (children.hasMoreElements()) {
- T childNode = (T)children.nextElement();
+ InspectionTreeNode childNode = (InspectionTreeNode)children.nextElement();
restoreExpansionStatus(childNode, tree);
}
}
}
- @SuppressWarnings("unchecked")
- private class TreeSelectionPath {
+ private static class InspectionTreeSelectionPath {
private final Object[] myPath;
private final int[] myIndices;
- public TreeSelectionPath(TreePath path) {
+ public InspectionTreeSelectionPath(TreePath path) {
myPath = path.getPath();
myIndices = new int[myPath.length];
for (int i = 0; i < myPath.length - 1; i++) {
- T node = (T)myPath[i];
- myIndices[i + 1] = getChildIndex(node, (T)myPath[i + 1]);
+ InspectionTreeNode node = (InspectionTreeNode)myPath[i];
+ myIndices[i + 1] = getChildIndex(node, (InspectionTreeNode)myPath[i + 1]);
}
}
- private int getChildIndex(T node, T child) {
+ private static int getChildIndex(InspectionTreeNode node, InspectionTreeNode child) {
int idx = 0;
Enumeration children = node.children();
while (children.hasMoreElements()) {
- T ch = (T)children.nextElement();
+ InspectionTreeNode ch = (InspectionTreeNode)children.nextElement();
if (ch == child) break;
idx++;
}
return idx;
}
- public void restore(JTree tree, boolean treeNodeMightChange) {
+ public void restore(InspectionTree tree, boolean treeNodeMightChange) {
tree.getSelectionModel().removeSelectionPaths(tree.getSelectionModel().getSelectionPaths());
TreeUtil.selectPath(tree, restorePath(tree, treeNodeMightChange));
}
- private TreePath restorePath(JTree tree, boolean treeNodeMightChange) {
+ private TreePath restorePath(InspectionTree tree, boolean treeNodeMightChange) {
ArrayList<Object> newPath = new ArrayList<>();
newPath.add(tree.getModel().getRoot());
private void restorePath(ArrayList<Object> newPath, int idx, boolean treeNodeMightChange) {
if (idx >= myPath.length) return;
- T oldNode = (T)myPath[idx];
- T newRoot = (T)newPath.get(idx - 1);
+ InspectionTreeNode oldNode = (InspectionTreeNode)myPath[idx];
+ InspectionTreeNode newRoot = (InspectionTreeNode)newPath.get(idx - 1);
Enumeration children = newRoot.children();
while (children.hasMoreElements()) {
- T child = (T)children.nextElement();
- if (treeNodeMightChange ? myComparator.compare(child, oldNode) == 0 : child == oldNode) {
+ InspectionTreeNode child = (InspectionTreeNode)children.nextElement();
+ if (treeNodeMightChange ? InspectionResultsViewComparator.getInstance().areEqual(child, oldNode) : child == oldNode) {
newPath.add(child);
restorePath(newPath, idx + 1, treeNodeMightChange);
return;
+++ /dev/null
-/*
- * 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.
- */
-package com.intellij.codeInspection.ui;
-
-/*
- * 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.
- */
-
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.event.TreeExpansionEvent;
-import javax.swing.event.TreeWillExpandListener;
-import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.ExpandVetoException;
-
-public class TreeWillExpandListenerImpl implements TreeWillExpandListener {
- @NotNull
- private final ExpansionTreeState<? extends DefaultMutableTreeNode> myState;
-
- public TreeWillExpandListenerImpl(@NotNull ExpansionTreeState<? extends DefaultMutableTreeNode> state) {
- myState = state;
- }
-
- @Override
- public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
- final DefaultMutableTreeNode node = (DefaultMutableTreeNode)event.getPath().getLastPathComponent();
- myState.getExpandedUserObjects().add(node.getUserObject());
- }
-
- @Override
- public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
- final DefaultMutableTreeNode node = (DefaultMutableTreeNode)event.getPath().getLastPathComponent();
- myState.getExpandedUserObjects().remove(node.getUserObject());
- }
-}