diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java index e07a62dfcbd3..0800964fc35c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java @@ -100,7 +100,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx private final FileStatusMap myFileStatusMap; private DaemonCodeAnalyzerSettings myLastSettings; - private IntentionHintComponent myLastIntentionHint; //guarded by this + private volatile IntentionHintComponent myLastIntentionHint; private volatile boolean myDisposed; // the only possible transition: false -> true private volatile boolean myInitialized; // the only possible transition: false -> true @@ -109,7 +109,6 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx @NonNls private static final String URL_ATT = "url"; private DaemonListeners myDaemonListeners; private final PassExecutorService myPassExecutorService; - private int myModificationCount = 0; private volatile boolean allowToInterrupt = true; private StatusBarUpdater myStatusBarUpdater; @@ -456,7 +455,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx } @NotNull - public List getPassesToShowProgressFor(Document document) { + List getPassesToShowProgressFor(Document document) { List allPasses = myPassExecutorService.getAllSubmittedPasses(); List result = new ArrayList(allPasses.size()); for (TextEditorHighlightingPass pass : allPasses) { @@ -467,7 +466,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx return result; } - public boolean isAllAnalysisFinished(@NotNull PsiFile file) { + boolean isAllAnalysisFinished(@NotNull PsiFile file) { if (myDisposed) return false; Document document = PsiDocumentManager.getInstance(myProject).getCachedDocument(file); return document != null && @@ -488,11 +487,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx return myFileStatusMap; } - public synchronized int getModificationCount() { - return myModificationCount; - } - - public synchronized boolean isRunning() { + synchronized boolean isRunning() { return myUpdateProgress != null && !myUpdateProgress.isCanceled(); } @@ -509,7 +504,6 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx private synchronized void cancelUpdateProgress(final boolean start, @NonNls String reason) { PassExecutorService.log(myUpdateProgress, null, reason, start); - myModificationCount++; if (myUpdateProgress != null) { myUpdateProgress.cancel(); @@ -541,12 +535,12 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx }); } - public static boolean processHighlightsOverlappingOutside(@NotNull Document document, - @NotNull Project project, - @Nullable("null means all") final HighlightSeverity minSeverity, - final int startOffset, - final int endOffset, - @NotNull final Processor processor) { + static boolean processHighlightsOverlappingOutside(@NotNull Document document, + @NotNull Project project, + @Nullable("null means all") final HighlightSeverity minSeverity, + final int startOffset, + final int endOffset, + @NotNull final Processor processor) { LOG.assertTrue(ApplicationManager.getApplication().isReadAccessAllowed()); final SeverityRegistrar severityRegistrar = SeverityRegistrar.getInstance(project); @@ -634,13 +628,17 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx return markup.getUserData(MARKERS_IN_EDITOR_DOCUMENT_KEY); } - public static void setLineMarkers(@NotNull Document document, List lineMarkers, Project project) { + static void setLineMarkers(@NotNull Document document, List lineMarkers, Project project) { ApplicationManager.getApplication().assertIsDispatchThread(); MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true); markup.putUserData(MARKERS_IN_EDITOR_DOCUMENT_KEY, lineMarkers); } - public synchronized void setLastIntentionHint(@NotNull Project project, @NotNull PsiFile file, @NotNull Editor editor, @NotNull ShowIntentionsPass.IntentionsInfo intentions, boolean hasToRecreate) { + void setLastIntentionHint(@NotNull Project project, + @NotNull PsiFile file, + @NotNull Editor editor, + @NotNull ShowIntentionsPass.IntentionsInfo intentions, + boolean hasToRecreate) { ApplicationManager.getApplication().assertIsDispatchThread(); hideLastIntentionHint(); IntentionHintComponent hintComponent = IntentionHintComponent.showIntentionHint(project, file, editor, intentions, false); @@ -650,15 +648,17 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx myLastIntentionHint = hintComponent; } - public synchronized void hideLastIntentionHint() { - if (myLastIntentionHint != null && myLastIntentionHint.isVisible()) { - myLastIntentionHint.hide(); + void hideLastIntentionHint() { + ApplicationManager.getApplication().assertIsDispatchThread(); + IntentionHintComponent hint = myLastIntentionHint; + if (hint != null && hint.isVisible()) { + hint.hide(); myLastIntentionHint = null; } } @Nullable - public synchronized IntentionHintComponent getLastIntentionHint() { + IntentionHintComponent getLastIntentionHint() { return myLastIntentionHint; } @@ -715,7 +715,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx Runnable runnable = new Runnable() { @Override public void run() { - PassExecutorService.log(myUpdateProgress, null, "Update Runnable. myUpdateByTimerEnabled:",myUpdateByTimerEnabled," something disposed:",PowerSaveMode.isEnabled() || myDisposed || !myProject.isInitialized()," activeEditors:",myProject.isDisposed() ? null : myDaemonListeners.getSelectedEditors()); + PassExecutorService.log(getUpdateProgress(), null, "Update Runnable. myUpdateByTimerEnabled:",myUpdateByTimerEnabled," something disposed:",PowerSaveMode.isEnabled() || myDisposed || !myProject.isInitialized()," activeEditors:",myProject.isDisposed() ? null : myDaemonListeners.getSelectedEditors()); if (!myUpdateByTimerEnabled) return; if (myDisposed) return; ApplicationManager.getApplication().assertIsDispatchThread(); @@ -786,6 +786,10 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx } } + synchronized DaemonProgressIndicator getUpdateProgress() { + return myUpdateProgress; + } + @NotNull @TestOnly public static List getFileLevelHighlights(@NotNull Project project, @NotNull PsiFile file ) { @@ -796,9 +800,4 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx public void allowToInterrupt(boolean can) { allowToInterrupt = can; } - - @TestOnly - public synchronized DaemonProgressIndicator getUpdateProgress() { - return myUpdateProgress; - } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java index 5480d1a4b3f1..edbc4a2e5557 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java @@ -181,7 +181,12 @@ class DaemonListeners implements Disposable { @Override public void editorReleased(@NotNull EditorFactoryEvent event) { // mem leak after closing last editor otherwise - myDaemonCodeAnalyzer.hideLastIntentionHint(); + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + myDaemonCodeAnalyzer.hideLastIntentionHint(); + } + }); } }; EditorFactory.getInstance().addEditorFactoryListener(editorFactoryListener, this);