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)
1  2 
platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java
platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java
spellchecker/src/com/intellij/spellchecker/jetbrains.dic

index 9633d51f64f5b1d50e3b5db3a133d31de3687cf8,6216db8bb7f372ecb3264264ad5ee17e3f62c33d..f28d50c6ad661d8b6009f13395be27c8eeeb4924
@@@ -66,6 -66,7 +66,7 @@@ import com.intellij.openapi.vfs.Virtual
  import com.intellij.openapi.wm.ToolWindowId;
  import com.intellij.openapi.wm.ToolWindowManager;
  import com.intellij.psi.*;
+ import com.intellij.psi.search.GlobalSearchScopesCore;
  import com.intellij.psi.search.LocalSearchScope;
  import com.intellij.psi.search.SearchScope;
  import com.intellij.psi.search.scope.packageSet.NamedScope;
@@@ -80,7 -81,6 +81,6 @@@ import com.intellij.util.TripleFunction
  import com.intellij.util.containers.ContainerUtil;
  import com.intellij.util.containers.HashMap;
  import com.intellij.util.containers.HashSet;
- import com.intellij.util.ui.UIUtil;
  import gnu.trove.THashSet;
  import org.jdom.Element;
  import org.jetbrains.annotations.NonNls;
@@@ -104,6 -104,7 +104,7 @@@ public class GlobalInspectionContextImp
  
    private final NotNullLazyValue<ContentManager> myContentManager;
    private volatile InspectionResultsView myView;
+   private volatile String myOutputPath;
    private Content myContent;
    private volatile boolean myViewClosed = true;
    private long myInspectionStartedTimestamp;
      setCurrentScope(scope);
  
      final Runnable action = () -> {
-       DefaultInspectionToolPresentation.setOutputPath(outputPath);
+       myOutputPath = outputPath;
        try {
          performInspectionsWithProgress(scope, runGlobalToolsOnly, isOfflineInspections);
          exportResults(inspectionsResults, outputPath);
        }
        finally {
-         DefaultInspectionToolPresentation.setOutputPath(null);
+         myOutputPath = null;
        }
      };
      if (isOfflineInspections) {
      }
    }
  
-   public void ignoreElement(@NotNull InspectionProfileEntry tool, @NotNull PsiElement element) {
+   public void resolveElement(@NotNull InspectionProfileEntry tool, @NotNull PsiElement element) {
      final RefElement refElement = getRefManager().getReference(element);
+     if (refElement == null) return;
      final Tools tools = getTools().get(tool.getShortName());
      if (tools != null){
        for (ScopeToolState state : tools.getTools()) {
          InspectionToolWrapper toolWrapper = state.getTool();
-         ignoreElementRecursively(toolWrapper, refElement);
+         InspectionToolPresentation presentation = getPresentationOrNull(toolWrapper);
+         if (presentation != null) {
+           resolveElementRecursively(presentation, refElement);
+         }
        }
      }
    }
      return myView;
    }
  
-   private void ignoreElementRecursively(@NotNull InspectionToolWrapper toolWrapper, final RefEntity refElement) {
-     if (refElement != null) {
-       InspectionToolPresentation presentation = getPresentation(toolWrapper);
-       presentation.ignoreCurrentElement(refElement);
-       final List<RefEntity> children = refElement.getChildren();
-       for (RefEntity child : children) {
-         ignoreElementRecursively(toolWrapper, child);
-       }
+   public String getOutputPath() {
+     return myOutputPath;
+   }
+   private static void resolveElementRecursively(@NotNull InspectionToolPresentation presentation, @NotNull RefEntity refElement) {
+     presentation.suppressProblem(refElement);
+     final List<RefEntity> children = refElement.getChildren();
+     for (RefEntity child : children) {
+       resolveElementRecursively(presentation, child);
      }
    }
  
    @Override
    protected void notifyInspectionsFinished(@NotNull final AnalysisScope scope) {
      if (ApplicationManager.getApplication().isUnitTestMode()) return;
-     UIUtil.invokeLaterIfNeeded(() -> {
-       long elapsed = System.currentTimeMillis() - myInspectionStartedTimestamp;
-       LOG.info("Code inspection finished. Took "+elapsed+"ms");
-       if (getProject().isDisposed()) return;
-       InspectionResultsView view = myView == null ? new InspectionResultsView(this, createContentProvider()) : null;
-       if (!(myView == null ? view : myView).hasProblems()) {
-         NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message",
-                                                                         scope.getFileCount(),
-                                                                         scope.getShortenName()),
-                                               MessageType.INFO).notify(getProject());
-         close(true);
-         if (view != null) {
-           Disposer.dispose(view);
-         }
+     LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
+     long elapsed = System.currentTimeMillis() - myInspectionStartedTimestamp;
+     LOG.info("Code inspection finished. Took " + elapsed + "ms");
+     if (getProject().isDisposed()) return;
+     InspectionResultsView view = myView == null ? new InspectionResultsView(this, createContentProvider()) : null;
+     if (!(myView == null ? view : myView).hasProblems()) {
+       NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message",
+                                                                       scope.getFileCount(),
+                                                                       scope.getShortenName()),
+                                             MessageType.INFO).notify(getProject());
+       close(true);
+       if (view != null) {
+         Disposer.dispose(view);
        }
-       else if (view != null && !view.isDisposed() && getCurrentScope() != null) {
-         addView(view);
-         view.update();
-       }
-       if (myView != null) {
-         myView.setUpdating(false);
-       }
-     });
+     }
+     else if (view != null && !view.isDisposed() && getCurrentScope() != null) {
+       addView(view);
+       view.update();
+     }
+     if (myView != null) {
+       myView.setUpdating(false);
+     }
    }
  
    @Override
    }
  
    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;
  
      final boolean canBeExternalUsages = !(scope.getScopeType() == AnalysisScope.PROJECT && scope.isIncludeTestSource());
      for (Tools tools : globalTools) {
        for (ScopeToolState state : tools.getTools()) {
+         if (!state.isEnabled()) continue;
+         NamedScope stateScope = state.getScope(getProject());
+         if (stateScope == null) continue;
+         AnalysisScope scopeForState = new AnalysisScope(GlobalSearchScopesCore.filterScope(getProject(), stateScope), getProject());
          final InspectionToolWrapper toolWrapper = state.getTool();
          final GlobalInspectionTool tool = (GlobalInspectionTool)toolWrapper.getTool();
          final InspectionToolPresentation toolPresentation = getPresentation(toolWrapper);
              }
            }
            ApplicationManager.getApplication().runReadAction(() -> {
-             tool.runInspection(scope, inspectionManager, this, toolPresentation);
+             tool.runInspection(scopeForState, inspectionManager, this, toolPresentation);
              //skip phase when we are sure that scope already contains everything, unused declaration though needs to proceed with its suspicious code
              if ((canBeExternalUsages || tool.getAdditionalJobs(this) != null) &&
                  tool.queryExternalUsagesRequests(inspectionManager, this, toolPresentation)) {
      myViewClosed = true;
      myView = null;
      ((InspectionManagerEx)InspectionManager.getInstance(getProject())).closeRunningContext(this);
-     for (Tools tools : getTools().values()) {
-       for (ScopeToolState state : tools.getTools()) {
-         InspectionToolWrapper toolWrapper = state.getTool();
-         getPresentation(toolWrapper).finalCleanup();
-       }
-     }
+     myPresentationMap.clear();
      super.close(noSuspiciousCodeFound);
    }
  
    }
  
    private final ConcurrentMap<InspectionToolWrapper, InspectionToolPresentation> myPresentationMap = ContainerUtil.newConcurrentMap();
+   @Nullable
+   public InspectionToolPresentation getPresentationOrNull(@NotNull InspectionToolWrapper toolWrapper) {
+     return myPresentationMap.get(toolWrapper);
+   }
    @NotNull
    public InspectionToolPresentation getPresentation(@NotNull InspectionToolWrapper toolWrapper) {
      InspectionToolPresentation presentation = myPresentationMap.get(toolWrapper);
        }, ModalityState.defaultModalityState());
        return;
      }
 -    
 +
      Runnable runnable = () -> {
        if (!FileModificationService.getInstance().preparePsiElementsForWrite(files)) return;
-       CleanupInspectionIntention.applyFixesNoSort(getProject(), "Code Cleanup", descriptors, null);
+       CleanupInspectionIntention.applyFixesNoSort(getProject(), "Code Cleanup", descriptors, null, false);
        if (postRunnable != null) {
          postRunnable.run();
        }
index 228bd386c9793dd7a93d979d82434c3cde12b061,0a4a4c342a4bf3d123a73e8bf76472cfd271a1a0..37fc8760360cf18ab60b1c1ffe6ee00a11686476
@@@ -67,12 -67,10 +67,10 @@@ import com.intellij.util.ObjectUtils
  import com.intellij.util.OpenSourceUtil;
  import com.intellij.util.concurrency.AppExecutorUtil;
  import com.intellij.util.containers.ContainerUtil;
- import com.intellij.util.containers.FactoryMap;
  import com.intellij.util.containers.HashSet;
  import com.intellij.util.ui.JBUI;
  import com.intellij.util.ui.UIUtil;
  import com.intellij.util.ui.tree.TreeUtil;
- import gnu.trove.THashSet;
  import org.jetbrains.annotations.NonNls;
  import org.jetbrains.annotations.NotNull;
  import org.jetbrains.annotations.Nullable;
@@@ -122,9 -120,7 +120,7 @@@ public class InspectionResultsView exte
    private final ExclusionHandler<InspectionTreeNode> myExclusionHandler;
    private EditorEx myPreviewEditor;
    private InspectionTreeLoadingProgressAware myLoadingProgressPreview;
-   private final ExcludedInspectionTreeNodesManager myExcludedInspectionTreeNodesManager;
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
-   private final Map<String, Set<Object>> mySuppressedNodes = FactoryMap.createMap(key -> new THashSet<>());
    private final InspectionViewSuppressActionHolder mySuppressActionHolder = new InspectionViewSuppressActionHolder();
  
    private final Object myTreeStructureUpdateLock = new Object();
      myScope = globalInspectionContext.getCurrentScope();
      myGlobalInspectionContext = globalInspectionContext;
      myProvider = provider;
-     myExcludedInspectionTreeNodesManager = new ExcludedInspectionTreeNodesManager(provider instanceof OfflineInspectionRVContentProvider,
-                                                                                   isSingleInspectionRun());
      myTree = new InspectionTree(globalInspectionContext, this);
      initTreeListeners();
  
  
        @Override
        public boolean isNodeExcluded(@NotNull InspectionTreeNode node) {
-         return node.isExcluded(myExcludedInspectionTreeNodesManager);
+         return node.isExcluded();
        }
  
        @Override
        public void excludeNode(@NotNull InspectionTreeNode node) {
-         node.excludeElement(myExcludedInspectionTreeNodesManager);
+         node.excludeElement();
        }
  
        @Override
        public void includeNode(@NotNull InspectionTreeNode node) {
-         node.amnestyElement(myExcludedInspectionTreeNodesManager);
+         node.amnestyElement();
        }
  
        @Override
        @Override
        @Nullable
        protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) {
-         if (node instanceof InspectionTreeNode && ((InspectionTreeNode)node).isExcluded(myExcludedInspectionTreeNodesManager)) {
+         if (node instanceof InspectionTreeNode && ((InspectionTreeNode)node).isExcluded()) {
            return null;
          }
          if (node instanceof RefElementNode) {
        }
      }
      if (previewEditor != null) {
 -      ProblemPreviewEditorPresentation.setupFoldingsForNonProblemRanges(previewEditor, this);
 +      ProblemPreviewEditorPresentation.setupFoldingsAndHighlightProblems(previewEditor, this);
      }
      mySplitter.setSecondComponent(editorPanel);
    }
      return mySuppressActionHolder;
    }
  
-   public Set<Object> getSuppressedNodes(String toolId) {
-     return mySuppressedNodes.get(toolId);
-   }
-   @NotNull
-   public ExcludedInspectionTreeNodesManager getExcludedManager() {
-     return myExcludedInspectionTreeNodesManager;
-   }
    @Nullable
    public String getCurrentProfileName() {
      return myInspectionProfile == null ? null : myInspectionProfile.getDisplayName();
            }
            final InspectionNode toolNode = presentation.getToolNode();
            LOG.assertTrue(toolNode != null);
-           final Map<RefEntity, CommonProblemDescriptor[]> problems = new HashMap<>();
+           final Map<RefEntity, CommonProblemDescriptor[]> problems = new HashMap<>(1);
            problems.put(refElement, descriptors);
            final Map<String, Set<RefEntity>> contents = new HashMap<>();
            final String groupName = refElement.getRefManager().getGroupName((RefElement)refElement);
                                                uiOptions.SHOW_STRUCTURE,
                                                true,
                                                contents,
-                                               problems);
+                                               problems::get);
          }
        }
      }));
        boolean singleInspectionRun = isSingleInspectionRun();
        for (Tools currentTools : tools) {
          InspectionToolWrapper defaultToolWrapper = currentTools.getDefaultState().getTool();
-         if (myGlobalInspectionContext.getUIOptions().FILTER_RESOLVED_ITEMS &&
-             myExcludedInspectionTreeNodesManager.containsInspectionNode(defaultToolWrapper)) {
-           continue;
-         }
          final HighlightDisplayKey key = HighlightDisplayKey.find(defaultToolWrapper.getShortName());
          for (ScopeToolState state : myProvider.getTools(currentTools)) {
            InspectionToolWrapper toolWrapper = state.getTool();
index 691499174978b3bd45a3481aeb82e3e1297ed138,6f952fb9c882972b6173b76073cbeae82f080857..953c45d33aca8db3ac9fb96bbc106ee534482202
@@@ -77,7 -77,7 +77,7 @@@ public final class TreeUtil 
    @Nullable
    public static <T> T findObjectInPath(@Nullable TreePath path, @NotNull Class<T> clazz) {
      for (TreePath p = path; p != null; p = p.getParentPath()) {
-       Object o = p.getLastPathComponent();
+       Object o = getUserObject(p.getLastPathComponent());
        if (clazz.isInstance(o)) return (T)o;
      }
      return null;
        row--;
      }
      Object root = tree.getModel().getRoot();
 -    if (root != null) {
 +    if (root != null && !tree.isRootVisible()) {
        tree.expandPath(new TreePath(root));
      }
      if (leadSelectionPath != null) {
  
    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 a526ab714e14d82190a73a8f386816a404de4937,56e8838af6ffb963deb8dc72b43134c5c4429069..0d86722b4755da6bbb3c8732396918d8712a170b
@@@ -9,6 -9,7 +9,7 @@@ aligna
  alloc
  anyschema
  aopalliance
+ apothem
  appender
  archivelog
  argc
@@@ -93,6 -94,7 +94,7 @@@ closeabl
  cloudfoundry
  cmake
  cmdline
+ cname
  codebase
  codeinsight
  codesign
@@@ -225,6 -227,7 +227,7 @@@ gruntfil
  gruntfiles
  gulpfile
  gulpfiles
+ guid
  gzip
  gzipped
  hadoop
@@@ -346,6 -349,7 +349,7 @@@ lucen
  lvalue
  lvalues
  macrodef
+ mailto
  makefile
  makefiles
  malloc
@@@ -461,6 -465,7 +465,7 @@@ onlin
  openid
  openjdk
  openssl
+ opensymphony
  optnone
  osgi
  outfile
@@@ -529,6 -534,7 +534,7 @@@ ptrdif
  pycharm
  queryable
  radiobutton
+ reactivestreams
  readme
  readonly
  readwrite
@@@ -545,6 -551,7 +551,7 @@@ refacto
  refactored
  refactoring
  refactorings
+ referer
  regex
  regexp
  reifiable
@@@ -700,6 -707,7 +707,7 @@@ systimestam
  tablespace
  taglib
  teamcity
+ templatemode
  temptable
  thiscall
  throwable
@@@ -760,7 -768,6 +768,7 @@@ ut
  util
  utils
  uuid
 +valgrind
  validator
  validators
  vararg