diff --git a/platform/analysis-api/src/com/intellij/codeInsight/daemon/DaemonCodeAnalyzer.java b/platform/analysis-api/src/com/intellij/codeInsight/daemon/DaemonCodeAnalyzer.java index 282fc839ecd4..6346de4f4bbf 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/daemon/DaemonCodeAnalyzer.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/daemon/DaemonCodeAnalyzer.java @@ -1,29 +1,18 @@ -/* - * 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. - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.daemon; import com.intellij.openapi.Disposable; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; import com.intellij.util.messages.Topic; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; + /** * Manages the background highlighting and auto-import for files displayed in editors. */ @@ -64,10 +53,35 @@ public abstract class DaemonCodeAnalyzer { public static final Topic DAEMON_EVENT_TOPIC = Topic.create("DAEMON_EVENT_TOPIC", DaemonListener.class); public interface DaemonListener { - void daemonFinished(); - void daemonCancelEventOccurred(@NotNull String reason); + /** + * Fired when the background code analysis is being scheduled for the specified set of files. + * @param fileEditors The list of files that will be analyzed during the current execution of the daemon. + */ + default void daemonStarting(@NotNull Collection fileEditors) { + daemonFinished(); + } + + /** + * Fired when the background code analysis is done. + */ + default void daemonFinished() { + } + + /** + * Fired when the background code analysis is done. + * @param fileEditors The list of files analyzed during the current execution of the daemon. + */ + default void daemonFinished(@NotNull Collection fileEditors) { + daemonFinished(); + } + + default void daemonCancelEventOccurred(@NotNull String reason) { + } } + /** + * @deprecated Please use DaemonListener directly + */ public abstract static class DaemonListenerAdapter implements DaemonListener { @Override public void daemonFinished() { 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 a91ade70ff09..5041e941bffc 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 @@ -350,7 +350,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers myUpdateRunnableFuture.cancel(false); - final DaemonProgressIndicator progress = createUpdateProgress(); + final DaemonProgressIndicator progress = createUpdateProgress(map.keySet()); myPassExecutorService.submitPasses(map, progress); try { long start = System.currentTimeMillis(); @@ -802,7 +802,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers // cancel all after calling createPasses() since there are perverts {@link com.intellij.util.xml.ui.DomUIFactoryImpl} who are changing PSI there cancelUpdateProgress(true, "Cancel by alarm"); myUpdateRunnableFuture.cancel(false); - DaemonProgressIndicator progress = createUpdateProgress(); + DaemonProgressIndicator progress = createUpdateProgress(passes.keySet()); myPassExecutorService.submitPasses(passes, progress); } }; @@ -849,7 +849,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers } @NotNull - private synchronized DaemonProgressIndicator createUpdateProgress() { + private synchronized DaemonProgressIndicator createUpdateProgress(Collection fileEditors) { DaemonProgressIndicator old = myUpdateProgress; if (!old.isCanceled()) { old.cancel(); @@ -858,12 +858,13 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers @Override public void stopIfRunning() { super.stopIfRunning(); - myProject.getMessageBus().syncPublisher(DAEMON_EVENT_TOPIC).daemonFinished(); + myProject.getMessageBus().syncPublisher(DAEMON_EVENT_TOPIC).daemonFinished(fileEditors); HighlightingSessionImpl.clearProgressIndicator(this); } }; progress.setModalityProgress(null); progress.start(); + myProject.getMessageBus().syncPublisher(DAEMON_EVENT_TOPIC).daemonStarting(fileEditors); myUpdateProgress = progress; return progress; }