call inspectionFinished only once: IDEA-136834 LocalInspectionTool: inspectionFinishe...
authorAlexey Kudravtsev <cdr@intellij.com>
Wed, 25 Feb 2015 11:40:55 +0000 (14:40 +0300)
committerAlexey Kudravtsev <cdr@intellij.com>
Wed, 25 Feb 2015 11:42:56 +0000 (14:42 +0300)
platform/analysis-api/src/com/intellij/codeInspection/ProblemsHolder.java
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java

index d5f2744f3852837e418182b3338f536e52418787..98e836400a476904f97fa06270aec3c2a1afd795 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
@@ -36,7 +36,6 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
-import java.util.ConcurrentModificationException;
 import java.util.List;
 
 /**
@@ -47,7 +46,7 @@ public class ProblemsHolder {
   private final InspectionManager myManager;
   private final PsiFile myFile;
   private final boolean myOnTheFly;
-  private MyList<ProblemDescriptor> myProblems = new MyList<ProblemDescriptor>();
+  private final List<ProblemDescriptor> myProblems = new ArrayList<ProblemDescriptor>();
 
   public ProblemsHolder(@NotNull InspectionManager manager, @NotNull PsiFile file, boolean onTheFly) {
     myManager = manager;
@@ -126,8 +125,9 @@ public class ProblemsHolder {
                               ProblemHighlightType highlightType,
                               String descriptionTemplate,
                               LocalQuickFix... fixes) {
-    registerProblem(myManager.createProblemDescriptor(reference.getElement(), reference.getRangeInElement(), descriptionTemplate, highlightType,
-                                                      myOnTheFly, fixes));
+    ProblemDescriptor descriptor = myManager.createProblemDescriptor(reference.getElement(), reference.getRangeInElement(), descriptionTemplate, highlightType,
+                                        myOnTheFly, fixes);
+    registerProblem(descriptor);
   }
 
   public void registerProblem(@NotNull PsiReference reference) {
@@ -183,10 +183,7 @@ public class ProblemsHolder {
 
   @NotNull
   public List<ProblemDescriptor> getResults() {
-    MyList<ProblemDescriptor> problems = myProblems;
-    problems.allowModifications(false);
-    myProblems = new MyList<ProblemDescriptor>();
-    return problems;
+    return myProblems;
   }
 
   @NotNull
@@ -221,17 +218,4 @@ public class ProblemsHolder {
   public final Project getProject() {
     return myManager.getProject();
   }
-
-  private static class MyList<T> extends ArrayList<T> {
-    private volatile boolean readOnly;
-    @Override
-    public boolean add(T o) {
-      if (readOnly) throw new ConcurrentModificationException();
-      return super.add(o);
-    }
-
-    private void allowModifications(boolean v) {
-      readOnly = !v;
-    }
-  }
 }
index 145936b20c8979ebc7df234d463def44e8e5919f..2f5328aed5ef541b3cf6846ec68756de531308f9 100644 (file)
@@ -285,7 +285,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
     PsiElementVisitor visitor = InspectionEngine.createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements, languages);
 
     synchronized (init) {
-      init.add(new InspectionContext(toolWrapper, holder, visitor, languages));
+      init.add(new InspectionContext(toolWrapper, holder, holder.getResultCount(), visitor, languages));
     }
     advanceProgress(1);
 
@@ -311,7 +311,9 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
           context.tool.getTool().inspectionFinished(session, context.holder);
 
           if (context.holder.hasResults()) {
-            appendDescriptors(myFile, context.holder.getResults(), context.tool);
+            List<ProblemDescriptor> allProblems = context.holder.getResults();
+            List<ProblemDescriptor> restProblems = allProblems.subList(context.problemsSize, allProblems.size());
+            appendDescriptors(myFile, restProblems, context.tool);
           }
           return true;
         }
@@ -710,16 +712,19 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
   private static class InspectionContext {
     private InspectionContext(@NotNull LocalInspectionToolWrapper tool,
                               @NotNull ProblemsHolder holder,
+                              int problemsSize, // need this to diff between found problems in visible part and the rest
                               @NotNull PsiElementVisitor visitor,
                               @Nullable Collection<String> languageIds) {
       this.tool = tool;
       this.holder = holder;
+      this.problemsSize = problemsSize;
       this.visitor = visitor;
       this.languageIds = languageIds;
     }
 
     @NotNull private final LocalInspectionToolWrapper tool;
     @NotNull private final ProblemsHolder holder;
+    private final int problemsSize;
     @NotNull private final PsiElementVisitor visitor;
     @Nullable private final Collection<String> languageIds;
   }