CPP-548 Integration with Valgrind memory analyser
authorVladimir Plyashkun <vladimir.plyashkun@jetbrains.com>
Thu, 21 Sep 2017 11:17:29 +0000 (14:17 +0300)
committerVladimir Plyashkun <vladimir.plyashkun@jetbrains.com>
Thu, 21 Sep 2017 11:17:29 +0000 (14:17 +0300)
- reverted changes related with inspection tree expansion

platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTree.java
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeState.java [moved from platform/lang-impl/src/com/intellij/codeInspection/ui/ExpansionTreeState.java with 64% similarity]
platform/lang-impl/src/com/intellij/codeInspection/ui/TreeWillExpandListenerImpl.java [deleted file]

index 3f1cf5a9d62c7eba9a48d0e44d069bfdc8dddbb9..9633d51f64f5b1d50e3b5db3a133d31de3687cf8 100644 (file)
@@ -30,7 +30,10 @@ import com.intellij.codeInspection.reference.RefElement;
 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;
@@ -107,7 +110,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
 
   @NotNull
   private AnalysisUIOptions myUIOptions;
-  private ExpansionTreeState<InspectionTreeNode> myTreeState;
+  private InspectionTreeState myTreeState;
 
   public GlobalInspectionContextImpl(@NotNull Project project, @NotNull NotNullLazyValue<ContentManager> contentManager) {
     super(project);
@@ -120,7 +123,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
     return myContentManager.getValue();
   }
 
-  public void setTreeState(ExpansionTreeState<InspectionTreeNode> treeState) {
+  public void setTreeState(InspectionTreeState treeState) {
     myTreeState = treeState;
   }
 
@@ -522,11 +525,11 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
   }
 
   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;
 
@@ -1018,7 +1021,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
       }, ModalityState.defaultModalityState());
       return;
     }
-    
+
     Runnable runnable = () -> {
       if (!FileModificationService.getInstance().preparePsiElementsForWrite(files)) return;
       CleanupInspectionIntention.applyFixesNoSort(getProject(), "Code Cleanup", descriptors, null);
index 4b7f358e80e03960928e1f8cc172f8c92a71e8cb..90dccde763d4abe6d4251370c172e1f44db97a3d 100644 (file)
@@ -38,7 +38,10 @@ import com.intellij.util.ui.tree.TreeUtil;
 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.*;
@@ -50,7 +53,7 @@ public class InspectionTree extends Tree {
 
   @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,
@@ -64,7 +67,7 @@ public class InspectionTree extends Tree {
     setRootVisible(false);
     setShowsRootHandles(true);
     UIUtil.setLineStyleAngled(this);
-    addTreeWillExpandListener(new TreeWillExpandListenerImpl(myState));
+    addTreeWillExpandListener(new ExpandListener());
 
     myState.getExpandedUserObjects().add(project);
 
@@ -356,14 +359,32 @@ public class InspectionTree extends Tree {
     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;
similarity index 64%
rename from platform/lang-impl/src/com/intellij/codeInspection/ui/ExpansionTreeState.java
rename to platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeState.java
index 254b5405cd8d6bee8531876afc036c13283234a6..bf420dfb96a2b770cd2eff6a6f014d7799e66f24 100644 (file)
 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 {
@@ -56,50 +48,49 @@ public class ExpansionTreeState<T extends DefaultMutableTreeNode> {
     }
   }
 
-  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());
@@ -109,13 +100,13 @@ public class ExpansionTreeState<T extends DefaultMutableTreeNode> {
 
     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;
diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/TreeWillExpandListenerImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/TreeWillExpandListenerImpl.java
deleted file mode 100644 (file)
index 3da5c41..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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());
-  }
-}