From b6aab58eb90bf5958177bd4bc6de85356ad0dab0 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 13 Jan 2020 00:44:20 +0300 Subject: [PATCH] EmptyIndicator must conform to at least some simple lifecycle constraints GitOrigin-RevId: 3c3babd3a60826b38765c392f5801aff32ffa798 --- .../server/AutoMakeMessageHandler.java | 1 + .../progress/EmptyProgressIndicator.java | 26 +++++++++++++++---- .../progress/impl/ProgressIndicatorTest.java | 13 ++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/server/AutoMakeMessageHandler.java b/java/compiler/impl/src/com/intellij/compiler/server/AutoMakeMessageHandler.java index 7266c39e1cec..447faeed506b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/AutoMakeMessageHandler.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/AutoMakeMessageHandler.java @@ -41,6 +41,7 @@ class AutoMakeMessageHandler extends DefaultMessageHandler { myBuildStatus = CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Status.SUCCESS; myWolf = WolfTheProblemSolver.getInstance(project); myContext = new AutomakeCompileContext(project); + myContext.getProgressIndicator().start(); } public boolean unprocessedFSChangesDetected() { diff --git a/platform/core-api/src/com/intellij/openapi/progress/EmptyProgressIndicator.java b/platform/core-api/src/com/intellij/openapi/progress/EmptyProgressIndicator.java index d011cfe31497..950c9c6b78c0 100644 --- a/platform/core-api/src/com/intellij/openapi/progress/EmptyProgressIndicator.java +++ b/platform/core-api/src/com/intellij/openapi/progress/EmptyProgressIndicator.java @@ -21,9 +21,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class EmptyProgressIndicator implements StandardProgressIndicator { - @NotNull private final ModalityState myModalityState; + @NotNull + private final ModalityState myModalityState; - private volatile boolean myIsRunning; + @NotNull + private volatile RunState myRunState = RunState.VIRGIN; + private enum RunState { + VIRGIN, STARTED, STOPPED + } private volatile boolean myIsCanceled; private volatile int myNonCancelableSectionCount; @@ -37,18 +42,29 @@ public class EmptyProgressIndicator implements StandardProgressIndicator { @Override public void start() { - myIsRunning = true; + if (myRunState == RunState.STARTED) { + throw new IllegalStateException("Indicator already started"); + } + myRunState = RunState.STARTED; myIsCanceled = false; } @Override public void stop() { - myIsRunning = false; + switch (myRunState) { + case VIRGIN: + throw new IllegalStateException("Indicator can't be stopped because it wasn't started"); + case STARTED: + myRunState = RunState.STOPPED; + break; + case STOPPED: + throw new IllegalStateException("Indicator already stopped"); + } } @Override public boolean isRunning() { - return myIsRunning; + return myRunState == RunState.STARTED; } @Override diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java index 8b6774f758e6..d69f994de860 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java @@ -19,7 +19,6 @@ import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator; import com.intellij.concurrency.JobScheduler; import com.intellij.concurrency.SensitiveProgressWrapper; import com.intellij.ide.util.DelegatingProgressIndicator; -import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ReadAction; @@ -29,7 +28,6 @@ import com.intellij.openapi.application.impl.LaterInvocator; import com.intellij.openapi.diagnostic.DefaultLogger; import com.intellij.openapi.progress.*; import com.intellij.openapi.progress.util.*; -import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.EmptyRunnable; import com.intellij.openapi.wm.ex.ProgressIndicatorEx; import com.intellij.testFramework.BombedProgressIndicator; @@ -865,4 +863,15 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { catch (ProcessCanceledException ignored) { } } + + public void testEmptyIndicatorMustConformToAtLeastSomeSimpleLifecycleConstrains() { + ProgressIndicator indicator = new EmptyProgressIndicator(); + for (int i=0; i<2; i++) { + assertThrows(IllegalStateException.class, indicator::stop); + indicator.start(); + assertThrows(IllegalStateException.class, indicator::start); + indicator.stop(); + assertThrows(IllegalStateException.class, indicator::stop); + } + } }