diff --git a/platform/core-api/src/com/intellij/openapi/application/BaseActionRunnable.java b/platform/core-api/src/com/intellij/openapi/application/BaseActionRunnable.java index bf98d6826857..46aacea95999 100644 --- a/platform/core-api/src/com/intellij/openapi/application/BaseActionRunnable.java +++ b/platform/core-api/src/com/intellij/openapi/application/BaseActionRunnable.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.application; +import com.intellij.openapi.project.Project; import com.intellij.util.ThrowableRunnable; import org.jetbrains.annotations.NotNull; @@ -27,6 +28,13 @@ public abstract class BaseActionRunnable { protected abstract void run(@NotNull Result result) throws Throwable; + /** + * @deprecated use {@link ReadAction#run(ThrowableRunnable)} + * or {@link WriteAction#run(ThrowableRunnable)} + * or {@link com.intellij.openapi.command.WriteCommandAction#runWriteCommandAction(Project, Runnable)} + * or similar + */ + @Deprecated @NotNull public abstract RunResult execute(); diff --git a/platform/lang-api/src/com/intellij/util/ActionRunner.java b/platform/lang-api/src/com/intellij/util/ActionRunner.java index b99c5a808a9c..c166e1e33f95 100644 --- a/platform/lang-api/src/com/intellij/util/ActionRunner.java +++ b/platform/lang-api/src/com/intellij/util/ActionRunner.java @@ -15,7 +15,8 @@ */ package com.intellij.util; -import com.intellij.openapi.application.*; +import com.intellij.openapi.application.ReadAction; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.util.ThrowableComputable; import org.jetbrains.annotations.NotNull; @@ -28,14 +29,7 @@ public abstract class ActionRunner { */ @Deprecated public static void runInsideWriteAction(@NotNull final InterruptibleRunnable runnable) throws Exception { - RunResult result = new WriteAction() { - @Override - protected void run(@NotNull Result result) throws Throwable { - runnable.run(); - } - }.execute(); - if (result.getThrowable() instanceof Exception) throw (Exception)result.getThrowable(); - result.throwException(); + WriteAction.computeAndWait(()->{runnable.run(); return null; }); } /** diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/application/RunnableActionsTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/application/RunnableActionsTest.kt deleted file mode 100644 index 286a69193cd6..000000000000 --- a/platform/platform-tests/testSrc/com/intellij/openapi/application/RunnableActionsTest.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2000-2016 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. - */ -package com.intellij.openapi.application - -import com.intellij.openapi.command.WriteCommandAction -import com.intellij.testFramework.fixtures.BareTestFixtureTestCase -import org.assertj.core.api.Assertions.assertThat -import org.junit.Test - -class RunnableActionsTest : BareTestFixtureTestCase() { - private val message = "" - - @Test fun readAction() = doTest(object : ReadAction() { - override fun run(result: Result) = throw Exception(message) - }) - - @Test fun writeAction() = doTest(object : WriteAction() { - override fun run(result: Result) = throw Exception(message) - }) - - @Test fun commandAction() = doTest(object : WriteCommandAction(null) { - override fun run(result: Result) = throw Exception(message) - }) - - private fun doTest(action: BaseActionRunnable) { - try { - action.execute() - fail("BaseActionRunnable.execute() should pass exceptions") - } - catch (e: RuntimeException) { - assertThat(e.message).endsWith(message) - } - - val result:RunResult = action.executeSilently() - assertThat(result.hasException()).isTrue() - assertThat(result.throwable.message).endsWith(message) - } -} \ No newline at end of file diff --git a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java index 3de0a48e1c42..3b034a3d7bb9 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java +++ b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java @@ -141,7 +141,7 @@ public class ExpectedHighlightingData { } public void init() { - WriteCommandAction.writeCommandAction(null).run(() -> { + WriteCommandAction.runWriteCommandAction(null, () -> { extractExpectedLineMarkerSet(myDocument); extractExpectedHighlightsSet(myDocument); refreshLineMarkers(); diff --git a/plugins/generate-tostring/testSrc/org/jetbrains/java/generate/inspection/ToStringGeneratingTest.groovy b/plugins/generate-tostring/testSrc/org/jetbrains/java/generate/inspection/ToStringGeneratingTest.groovy index c54712d1ba32..6f07361f68b3 100644 --- a/plugins/generate-tostring/testSrc/org/jetbrains/java/generate/inspection/ToStringGeneratingTest.groovy +++ b/plugins/generate-tostring/testSrc/org/jetbrains/java/generate/inspection/ToStringGeneratingTest.groovy @@ -15,7 +15,7 @@ */ package org.jetbrains.java.generate.inspection -import com.intellij.openapi.application.Result + import com.intellij.openapi.command.WriteCommandAction import com.intellij.psi.PsiClass import com.intellij.psi.PsiFile @@ -30,7 +30,6 @@ import org.jetbrains.java.generate.config.ConflictResolutionPolicy import org.jetbrains.java.generate.config.ReplacePolicy import org.jetbrains.java.generate.template.TemplateResource import org.jetbrains.java.generate.template.toString.ToStringTemplatesManager - /** * Created by Max Medvedev on 07/03/14 */ @@ -148,12 +147,9 @@ class Foo { Collection members = collectMembers(clazz) GenerateToStringWorker worker = buildWorker(clazz, policy) - new WriteCommandAction(myFixture.project, myFixture.file) { - @Override - protected void run(@NotNull Result result) throws Throwable { + WriteCommandAction.runWriteCommandAction(myFixture.project, "","", { worker.execute(members, template, policy) - } - }.execute() + }, myFixture.file) myFixture.checkResult(after) } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy index 06f311e5b0b2..4cf63dfa0ec5 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy @@ -11,7 +11,6 @@ import com.intellij.execution.process.* import com.intellij.execution.runners.ProgramRunner import com.intellij.module.ModuleGroupTestsKt import com.intellij.openapi.Disposable -import com.intellij.openapi.application.Result import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.compiler.CompilerMessage import com.intellij.openapi.compiler.CompilerMessageCategory @@ -110,9 +109,7 @@ abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestCase imp } protected void setupTestSources() { - new WriteCommandAction(getProject()) { - @Override - protected void run(@NotNull Result result) throws Throwable { + WriteCommandAction.runWriteCommandAction(getProject(), { final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule) final ModifiableRootModel rootModel = rootManager.getModifiableModel() final ContentEntry entry = rootModel.getContentEntries()[0] @@ -120,8 +117,7 @@ abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestCase imp entry.addSourceFolder(myFixture.getTempDirFixture().findOrCreateDir("src"), false) entry.addSourceFolder(myFixture.getTempDirFixture().findOrCreateDir("tests"), true) rootModel.commit() - } - }.execute() + }) } protected Module addDependentModule() { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/copy/GroovyCopyClassTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/copy/GroovyCopyClassTest.groovy index 8930ce11b16e..d7fea95677df 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/copy/GroovyCopyClassTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/copy/GroovyCopyClassTest.groovy @@ -15,16 +15,13 @@ */ package org.jetbrains.plugins.groovy.refactoring.copy -import com.intellij.openapi.application.Result + import com.intellij.openapi.command.WriteCommandAction import com.intellij.psi.PsiClass -import com.intellij.psi.PsiFile import com.intellij.psi.search.GlobalSearchScope import com.intellij.refactoring.copy.CopyClassesHandler import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase -import org.jetbrains.annotations.NotNull import org.jetbrains.plugins.groovy.util.TestUtils - /** * @author peter */ @@ -43,14 +40,11 @@ class GroovyCopyClassTest extends LightCodeInsightFixtureTestCase { final PsiClass srcClass = myFixture.javaFacade.findClass("foo.$testName", GlobalSearchScope.allScope(project)) assertTrue(CopyClassesHandler.canCopyClass(srcClass)) - new WriteCommandAction(project, [] as PsiFile[]) { - @Override - protected void run(@NotNull Result result) throws Throwable { + WriteCommandAction.runWriteCommandAction(project, { def map = Collections.singletonMap(srcClass.navigationElement.containingFile, [srcClass] as PsiClass[]) def dir = srcClass.manager.findDirectory(myFixture.tempDirFixture.getFile("bar")) CopyClassesHandler.doCopyClasses(map, "${testName}_after", dir, project) - } - }.execute() + }); myFixture.checkResultByFile("bar/${testName}_after.groovy", "${testName}_after.groovy", true) }