From d9daa533c1bcde9140c42d986e9665a6eefd9341 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Thu, 29 Sep 2016 15:53:50 +0200 Subject: [PATCH] whole file pass: ensure restarted on all files after a change (IDEA-161890) --- .../daemon/impl/DaemonRespondToChangesTest.java | 9 +++++++++ .../impl/WholeFileLocalInspectionsPassFactory.java | 9 +++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java index 97e3eee4199a..d39851084606 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java @@ -586,6 +586,15 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase { int countAfter = tool.visited.size(); assertTrue(tool.visited.toString(), countAfter > 0); + tool.visited.clear(); + + //ensure started on another file + configureByExistingFile(otherFile.getVirtualFile()); + infos = doHighlighting(HighlightSeverity.WARNING); + assertEmpty(infos); + + int countAfter2 = tool.visited.size(); + assertTrue(tool.visited.toString(), countAfter2 > 0); } public void testOverriddenMethodMarkers() throws Exception { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/WholeFileLocalInspectionsPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/WholeFileLocalInspectionsPassFactory.java index 1bc7a4b3ec9a..ea21c74c2c8f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/WholeFileLocalInspectionsPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/WholeFileLocalInspectionsPassFactory.java @@ -51,7 +51,7 @@ import java.util.stream.Collectors; public class WholeFileLocalInspectionsPassFactory extends AbstractProjectComponent implements TextEditorHighlightingPassFactory { private final Map myFileToolsCache = ContainerUtil.createConcurrentWeakMap(); private final InspectionProjectProfileManager myProfileManager; - private volatile long myPsiModificationCount; + private final Map myPsiModificationCount = ContainerUtil.createConcurrentWeakMap(); public WholeFileLocalInspectionsPassFactory(Project project, TextEditorHighlightingPassRegistrar highlightingPassRegistrar, final InspectionProjectProfileManager profileManager) { @@ -88,8 +88,9 @@ public class WholeFileLocalInspectionsPassFactory extends AbstractProjectCompone @Override @Nullable public TextEditorHighlightingPass createHighlightingPass(@NotNull final PsiFile file, @NotNull final Editor editor) { - final long psiModificationCount = PsiManager.getInstance(myProject).getModificationTracker().getModificationCount(); - if (psiModificationCount == myPsiModificationCount) { + final Long appliedModificationCount = myPsiModificationCount.get(file); + if (appliedModificationCount != null && + appliedModificationCount == PsiManager.getInstance(myProject).getModificationTracker().getModificationCount()) { return null; //optimization } @@ -126,7 +127,7 @@ public class WholeFileLocalInspectionsPassFactory extends AbstractProjectCompone @Override protected void applyInformationWithProgress() { super.applyInformationWithProgress(); - myPsiModificationCount = PsiManager.getInstance(myProject).getModificationTracker().getModificationCount(); + myPsiModificationCount.put(file, PsiManager.getInstance(myProject).getModificationTracker().getModificationCount()); } }; }