inspection toolwindow: now insertByOrder is a class method
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Wed, 25 May 2016 09:15:38 +0000 (12:15 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Wed, 25 May 2016 09:15:38 +0000 (12:15 +0300)
platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionRVContentProvider.java
platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionRVContentProviderImpl.java
platform/lang-impl/src/com/intellij/codeInspection/offlineViewer/OfflineInspectionRVContentProvider.java
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeState.java

index f51fa8b95e024a09b9cfb303f4a2afbe69889919..cc6b9a7df15240865d77268bb90cf60d83c7ef17 100644 (file)
@@ -187,7 +187,7 @@ public abstract class InspectionRVContentProvider {
         }
         for (InspectionPackageNode packageNode : packageNodes.values()) {
           if (packageNode.getPackageName() != null) {
-            insertByIndex(packageNode, moduleNode);
+            moduleNode.insertByOrder(packageNode);
             for (UserObjectContainer<T> container : packageDescriptors.get(packageNode)) {
               appendDescriptor(context, toolWrapper, container, packageNode, canPackageRepeat);
             }
@@ -289,7 +289,7 @@ public abstract class InspectionRVContentProvider {
                 return false;
               }
               else {
-                insertByIndex(finalPrevNode, refElementNode);
+                refElementNode.insertByOrder(finalPrevNode);
                 result.set(nodeToBeAdded);
                 return false;
               }
@@ -301,11 +301,11 @@ public abstract class InspectionRVContentProvider {
       if(!result.isNull()) return result.get();
 
       if (!firstLevel.get()) {
-        insertByIndex(prevNode, currentNode);
+        currentNode.insertByOrder(prevNode);
       }
       final UserObjectContainer owner = container.getOwner();
       if (owner == null) {
-        insertByIndex(currentNode, parentNode);
+        parentNode.insertByOrder(currentNode);
         return nodeToBeAdded;
       }
       container = owner;
@@ -349,18 +349,7 @@ public abstract class InspectionRVContentProvider {
         }
       }
     }
-    insertByIndex(child, parent);
-  }
-
-  public static void insertByIndex(InspectionTreeNode child, InspectionTreeNode parent) {
-    if (parent.getIndex(child) != -1) {
-      return;
-    }
-    final int i = TreeUtil.indexedBinarySearch(parent, child, InspectionResultsViewComparator.getInstance());
-    if (i >= 0){
-      return;
-    }
-    parent.insert(child, -i -1);
+    parent.insertByOrder(child);
   }
 
   private static void processDepth(final InspectionTreeNode child, final InspectionTreeNode current) {
index 2997ee63fbb1d7e5be495cbae081839a254d4b66..dde1c52293db5965af151626af69cff97fc8c36f 100644 (file)
@@ -125,7 +125,7 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
         final RefElementNode elemNode = addNodeToParent(container, presentation, pNode);
         for (CommonProblemDescriptor problem : problems) {
           assert problem != null;
-          insertByIndex(new ProblemDescriptionNode(refElement, problem, toolWrapper,presentation), elemNode);
+          elemNode.insertByOrder(new ProblemDescriptionNode(refElement, problem, toolWrapper,presentation));
           if (problems.length == 1) {
             elemNode.setProblem(problems[0]);
           }
index 830b93f6e25914fe9306c3f58d3c2268a7671d25..fe7b23bc0a11bd52cd031f6b2d68eb731bceb6d4 100644 (file)
@@ -171,7 +171,7 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
       final OfflineProblemDescriptorNode child =
         OfflineProblemDescriptorNode.create(((OfflineProblemDescriptorContainer)container).getUserObject(),
                                             (LocalInspectionToolWrapper)toolWrapper, presentation);
-      insertByIndex(child, elemNode);
+      elemNode.insertByOrder(child);
     }
   }
 
index 6a4f1db176fca4d16b0b69d54b2795e4cc8e08eb..dd813a80b30bf206a1b5d288a04307a7b01a41e3 100644 (file)
@@ -88,8 +88,6 @@ import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
-import static com.intellij.codeInspection.ex.InspectionRVContentProvider.insertByIndex;
-
 /**
  * @author max
  */
@@ -751,7 +749,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
       }
       group = ConcurrencyUtil.cacheOrGet(map, groupName, new InspectionGroupNode(groupName, groupPath));
       if (!myDisposed) {
-        insertByIndex(group, getRelativeRootNode(groupedBySeverity, errorLevel));
+        getRelativeRootNode(groupedBySeverity, errorLevel).insertByOrder(group);
       }
     }
     return group;
@@ -766,7 +764,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
         severityGroupNode = ConcurrencyUtil.cacheOrGet(mySeverityGroupNodes, level, newNode);
         if (severityGroupNode == newNode) {
           InspectionTreeNode root = myTree.getRoot();
-          insertByIndex(severityGroupNode, root);
+          root.insertByOrder(severityGroupNode);
         }
       }
       return severityGroupNode;
index 369121f5a6aae7670245d8f82e73695ea5da2734..98b1dded76a42aa1e52393e2928040105ddda914 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel;
 import com.intellij.codeInspection.reference.RefEntity;
 import com.intellij.openapi.vcs.FileStatus;
 import com.intellij.util.containers.FactoryMap;
+import com.intellij.util.ui.tree.TreeUtil;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
@@ -64,7 +65,7 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode {
     return true;
   }
 
-  public boolean isExcluded(ExcludedInspectionTreeNodesManager excludedManager){
+  public boolean isExcluded(ExcludedInspectionTreeNodesManager excludedManager) {
     return excludedManager.isExcluded(this);
   }
 
@@ -77,7 +78,7 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode {
     return null;
   }
 
-  public FileStatus getNodeStatus(){
+  public FileStatus getNodeStatus() {
     return FileStatus.NOT_CHANGED;
   }
 
@@ -99,6 +100,17 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode {
     }
   }
 
+  public void insertByOrder(InspectionTreeNode child) {
+    if (getIndex(child) != -1) {
+      return;
+    }
+    final int i = TreeUtil.indexedBinarySearch(this, child, InspectionResultsViewComparator.getInstance());
+    if (i >= 0){
+      return;
+    }
+    insert(child, -i -1);
+  }
+
   @Override
   public void add(MutableTreeNode newChild) {
     super.add(newChild);
@@ -142,12 +154,12 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode {
   }
 
   @Override
-  public synchronized void setParent(MutableTreeNode newParent) {
-    super.setParent(newParent);
+  public synchronized TreeNode getParent() {
+    return super.getParent();
   }
 
   @Override
-  public synchronized TreeNode getParent() {
-    return super.getParent();
+  public synchronized void setParent(MutableTreeNode newParent) {
+    super.setParent(newParent);
   }
 }
index bebff8e81dfdd49209980390544329b574ef07de..90f804f5adbb7a232e743962f3129cccfea112f5 100644 (file)
@@ -50,7 +50,7 @@ public class InspectionTreeState {
 
   private boolean needRestore(@NotNull InspectionTreeNode node) {
     for (Object o : mySelectionPath.myPath) {
-      if (InspectionResultsViewComparator.getInstance().areEqual(o, node)) {
+      if (InspectionResultsViewComparator.getInstance().areEqual((InspectionTreeNode)o, node)) {
         return true;
       }
     }