Merge branch 'master' into vplyashkun/valgrind
authorVladimir Plyashkun <vladimir.plyashkun@jetbrains.com>
Mon, 25 Sep 2017 10:12:45 +0000 (13:12 +0300)
committerVladimir Plyashkun <vladimir.plyashkun@jetbrains.com>
Mon, 25 Sep 2017 10:12:45 +0000 (13:12 +0300)
platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java
platform/lang-impl/src/com/intellij/codeInspection/ui/PreviewEditorFoldingRegion.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemPreviewEditorPresentation.java
platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java
spellchecker/src/com/intellij/spellchecker/jetbrains.dic

index 6216db8bb7f372ecb3264264ad5ee17e3f62c33d..f28d50c6ad661d8b6009f13395be27c8eeeb4924 100644 (file)
@@ -530,11 +530,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;
 
@@ -1030,7 +1030,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, false);
index 0a4a4c342a4bf3d123a73e8bf76472cfd271a1a0..37fc8760360cf18ab60b1c1ffe6ee00a11686476 100644 (file)
@@ -564,7 +564,7 @@ public class InspectionResultsView extends JPanel implements Disposable, DataPro
       }
     }
     if (previewEditor != null) {
-      ProblemPreviewEditorPresentation.setupFoldingsForNonProblemRanges(previewEditor, this);
+      ProblemPreviewEditorPresentation.setupFoldingsAndHighlightProblems(previewEditor, this);
     }
     mySplitter.setSecondComponent(editorPanel);
   }
diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/PreviewEditorFoldingRegion.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/PreviewEditorFoldingRegion.java
new file mode 100644 (file)
index 0000000..54d2790
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import org.jetbrains.annotations.NotNull;
+
+public class PreviewEditorFoldingRegion implements Comparable<PreviewEditorFoldingRegion> {
+  private final int myStartLine;
+  private final int myEndLine;
+
+  public PreviewEditorFoldingRegion(int startLine, int endLine) {
+    myStartLine = startLine;
+    myEndLine = endLine;
+  }
+
+  public int getStartLine() {
+    return myStartLine;
+  }
+
+  public int getEndLine() {
+    return myEndLine;
+  }
+
+  public boolean contain(int position) {
+    return myStartLine <= position && myEndLine > position;
+  }
+
+  @Override
+  public int compareTo(@NotNull PreviewEditorFoldingRegion o) {
+    return Integer.compare(myStartLine, o.myStartLine);
+  }
+}
index f262bf7293d2240f3114bb12ecad53f78eed6f1d..c524097e1a90dfdbf189589f77bd28e0f97305cf 100644 (file)
@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.FoldRegion;
 import com.intellij.openapi.editor.ScrollType;
 import com.intellij.openapi.editor.ex.EditorEx;
 import com.intellij.openapi.editor.markup.HighlighterLayer;
+import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Segment;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.psi.PsiDocumentManager;
@@ -32,20 +33,15 @@ import com.intellij.usageView.UsageInfo;
 import com.intellij.usages.impl.UsagePreviewPanel;
 import org.jetbrains.annotations.NotNull;
 
+import java.awt.*;
 import java.util.*;
+import java.util.List;
 import java.util.stream.Collectors;
 
-class ProblemPreviewEditorPresentation {
+public class ProblemPreviewEditorPresentation {
   private final static int VIEW_ADDITIONAL_OFFSET = 4;
 
-  static void setupFoldingsForNonProblemRanges(@NotNull EditorEx editor, @NotNull InspectionResultsView view) {
-    final Document doc = editor.getDocument();
-    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(view.getProject());
-    if (documentManager.isUncommited(doc)) {
-      WriteAction.run(() -> documentManager.commitDocument(doc));
-    }
-    final SortedSet<PreviewEditorFoldingRegion> foldingRegions = new TreeSet<>(Comparator.comparing(x -> x.startLine));
-    foldingRegions.add(new PreviewEditorFoldingRegion(0, doc.getLineCount()));
+  static void setupFoldingsAndHighlightProblems(@NotNull EditorEx editor, @NotNull InspectionResultsView view) {
     List<UsageInfo> usages = Arrays.stream(view.getTree().getAllValidSelectedDescriptors())
       .filter(ProblemDescriptorBase.class::isInstance)
       .map(ProblemDescriptorBase.class::cast)
@@ -58,7 +54,19 @@ class ProblemPreviewEditorPresentation {
         return range == null ? new UsageInfo(psi) : new UsageInfo(psi, range.getStartOffset(), range.getEndOffset());
       })
       .collect(Collectors.toList());
+    setupFoldingsAndHighlightProblems(editor, view, usages, view.getProject());
+  }
+
 
+  public static void setupFoldingsAndHighlightProblems(@NotNull EditorEx editor, @NotNull Container editorContainer,
+                                                       @NotNull List<UsageInfo> usages, @NotNull Project project) {
+    final Document doc = editor.getDocument();
+    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
+    if (documentManager.isUncommited(doc)) {
+      WriteAction.run(() -> documentManager.commitDocument(doc));
+    }
+    final SortedSet<PreviewEditorFoldingRegion> foldingRegions = new TreeSet<>();
+    foldingRegions.add(new PreviewEditorFoldingRegion(0, doc.getLineCount()));
     boolean isUpdated = false;
     for (UsageInfo usage : usages) {
       if (usage == null) {
@@ -70,16 +78,16 @@ class ProblemPreviewEditorPresentation {
       setupFoldings(editor, foldingRegions);
     }
 
-    highlightProblems(editor, view, usages);
+    highlightProblems(editor, editorContainer, usages, project);
   }
 
-  private static void highlightProblems(EditorEx editor, InspectionResultsView view, List<UsageInfo> usages) {
+  private static void highlightProblems(EditorEx editor, Container editorContainer, List<UsageInfo> usages, @NotNull Project project) {
     List<UsageInfo> validUsages = usages.stream().filter(Objects::nonNull).collect(Collectors.toList());
-    PsiDocumentManager.getInstance(view.getProject()).performLaterWhenAllCommitted(() -> {
+    PsiDocumentManager.getInstance(project).performLaterWhenAllCommitted(() -> {
       if (!editor.isDisposed()) {
-        view.invalidate();
-        view.validate();
-        UsagePreviewPanel.highlight(validUsages, editor, view.getProject(), false, HighlighterLayer.SELECTION);
+        editorContainer.invalidate();
+        editorContainer.validate();
+        UsagePreviewPanel.highlight(validUsages, editor, project, false, HighlighterLayer.SELECTION);
         if (validUsages.size() == 1) {
           final PsiElement element = validUsages.get(0).getElement();
           if (element != null) {
@@ -95,24 +103,20 @@ class ProblemPreviewEditorPresentation {
     });
   }
 
-  private static boolean inRegion(int position, PreviewEditorFoldingRegion range) {
-    return range.startLine <= position && range.endLine > position;
-  }
-
-  private static void setupFoldings(EditorEx editor, SortedSet<PreviewEditorFoldingRegion> foldedRegions) {
+  public static void setupFoldings(EditorEx editor, SortedSet<PreviewEditorFoldingRegion> foldingRegions) {
     editor.getFoldingModel().runBatchFoldingOperation(() -> {
       editor.getFoldingModel().clearFoldRegions();
       editor.getMarkupModel().removeAllHighlighters();
-      for (PreviewEditorFoldingRegion region : foldedRegions) {
-        if (region.endLine - region.startLine > 1) {
+      for (PreviewEditorFoldingRegion region : foldingRegions) {
+        if (region.getEndLine() - region.getStartLine() > 1) {
           FoldRegion currentRegion = FoldingModelSupport.addFolding(editor,
-                                                                    region.startLine,
-                                                                    region.endLine,
+                                                                    region.getStartLine(),
+                                                                    region.getEndLine(),
                                                                     false);
           if (currentRegion != null) {
             DiffDrawUtil.createLineSeparatorHighlighter(editor,
-                                                        editor.getDocument().getLineStartOffset(region.startLine),
-                                                        editor.getDocument().getLineEndOffset(region.endLine - 1),
+                                                        editor.getDocument().getLineStartOffset(region.getStartLine()),
+                                                        editor.getDocument().getLineEndOffset(region.getEndLine() - 1),
                                                         () -> currentRegion.isValid() && !currentRegion.isExpanded());
           }
         }
@@ -126,43 +130,33 @@ class ProblemPreviewEditorPresentation {
     final int startLine = Math.max(0, document.getLineNumber(toShowRange.getStartOffset()) - 1);
     final int endLine = Math.min(document.getLineCount(), document.getLineNumber(toShowRange.getEndOffset()) + 2);
     for (PreviewEditorFoldingRegion range : new ArrayList<>(foldingRegions)) {
-      final boolean startInRegion = inRegion(startLine, range);
-      final boolean endInRegion = inRegion(endLine, range);
+      final boolean startInRegion = range.contain(startLine);
+      final boolean endInRegion = range.contain(endLine);
       if (startInRegion && endInRegion) {
         foldingRegions.remove(range);
-        if (range.startLine != startLine) {
-          foldingRegions.add(new PreviewEditorFoldingRegion(range.startLine, startLine));
+        if (range.getStartLine() != startLine) {
+          foldingRegions.add(new PreviewEditorFoldingRegion(range.getStartLine(), startLine));
         }
-        if (endLine != range.endLine) {
-          foldingRegions.add(new PreviewEditorFoldingRegion(endLine, range.endLine));
+        if (endLine != range.getEndLine()) {
+          foldingRegions.add(new PreviewEditorFoldingRegion(endLine, range.getEndLine()));
         }
         return true;
       }
       if (startInRegion) {
         foldingRegions.remove(range);
-        if (range.startLine != startLine) {
-          foldingRegions.add(new PreviewEditorFoldingRegion(range.startLine, startLine));
+        if (range.getStartLine() != startLine) {
+          foldingRegions.add(new PreviewEditorFoldingRegion(range.getStartLine(), startLine));
         }
         isUpdated = true;
       }
       if (endInRegion) {
         foldingRegions.remove(range);
-        if (endLine != range.endLine) {
-          foldingRegions.add(new PreviewEditorFoldingRegion(endLine, range.endLine));
+        if (endLine != range.getEndLine()) {
+          foldingRegions.add(new PreviewEditorFoldingRegion(endLine, range.getEndLine()));
         }
         return true;
       }
     }
     return isUpdated;
   }
-
-  private static class PreviewEditorFoldingRegion {
-    public final int startLine;
-    public final int endLine;
-
-    private PreviewEditorFoldingRegion(int startLine, int endLine) {
-      this.startLine = startLine;
-      this.endLine = endLine;
-    }
-  }
 }
index 6f952fb9c882972b6173b76073cbeae82f080857..953c45d33aca8db3ac9fb96bbc106ee534482202 100644 (file)
@@ -694,7 +694,7 @@ public final class TreeUtil {
       row--;
     }
     Object root = tree.getModel().getRoot();
-    if (root != null) {
+    if (root != null && !tree.isRootVisible()) {
       tree.expandPath(new TreePath(root));
     }
     if (leadSelectionPath != null) {
@@ -987,12 +987,17 @@ public final class TreeUtil {
 
   public static <T extends MutableTreeNode> void insertNode(@NotNull T child, @NotNull T parent, @Nullable DefaultTreeModel model,
                                                             @NotNull Comparator<? super T> comparator) {
+    insertNode(child, parent, model, false, comparator);
+  }
+
+  public static <T extends MutableTreeNode> void insertNode(@NotNull T child, @NotNull T parent, @Nullable DefaultTreeModel model,
+                                                            boolean allowDuplication, @NotNull Comparator<? super T> comparator) {
     int index = indexedBinarySearch(parent, child, comparator);
-    if (index >= 0) {
+    if (index >= 0 && !allowDuplication) {
       LOG.error("Node " + child + " is already added to " + parent);
       return;
     }
-    int insertionPoint = -(index + 1);
+    int insertionPoint = index >= 0 ? index : -(index + 1);
     if (model != null) {
       model.insertNodeInto(child, parent, insertionPoint);
     }
index 56e8838af6ffb963deb8dc72b43134c5c4429069..0d86722b4755da6bbb3c8732396918d8712a170b 100644 (file)
@@ -768,6 +768,7 @@ utf
 util
 utils
 uuid
+valgrind
 validator
 validators
 vararg