From 496cc88f26d011693c4a493bf0899447a1aedf2c Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 8 Nov 2016 15:00:12 +0100 Subject: [PATCH] cleanup, reduce usage of DefaultProgramRunner --- .../runners/DefaultProgramRunner.java | 33 -------------- .../execution/runners/DefaultProgramRunner.kt | 44 +++++++++++++++++++ .../runners/DefaultProgramRunnerImpl.kt | 12 ----- .../lang/xpath/xslt/run/XsltRunner.java | 4 +- .../xsltDebugger/XsltDebuggerRunner.java | 12 ++--- .../jetbrains/python/run/PythonRunner.java | 13 +++--- 6 files changed, 58 insertions(+), 60 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunner.java create mode 100644 platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunner.kt diff --git a/platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunner.java b/platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunner.java deleted file mode 100644 index fe793ce1a3cc..000000000000 --- a/platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunner.java +++ /dev/null @@ -1,33 +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.execution.runners; - -import com.intellij.execution.ExecutionException; -import com.intellij.execution.configurations.RunProfileState; -import com.intellij.execution.ui.RunContentDescriptor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @author spleaner - */ -public abstract class DefaultProgramRunner extends GenericProgramRunner { - @Nullable - @Override - protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException { - return DefaultProgramRunnerImplKt.executeState(state, env, this); - } -} diff --git a/platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunner.kt b/platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunner.kt new file mode 100644 index 000000000000..a2fef20414d1 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunner.kt @@ -0,0 +1,44 @@ +/* + * 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.execution.runners + +import com.intellij.execution.ExecutionException +import com.intellij.execution.ExecutionResult +import com.intellij.execution.RunProfileStarter +import com.intellij.execution.configurations.RunProfileState +import com.intellij.execution.configurations.RunnerSettings +import com.intellij.execution.ui.RunContentDescriptor +import com.intellij.openapi.fileEditor.FileDocumentManager + +abstract class DefaultProgramRunner : GenericProgramRunner() { + @Throws(ExecutionException::class) + override fun doExecute(state: RunProfileState, env: ExecutionEnvironment): RunContentDescriptor? { + return executeState(state, env, this) + } +} + +inline fun runProfileStarter(crossinline starter: (state: RunProfileState, environment: ExecutionEnvironment) -> RunContentDescriptor?) = object : RunProfileStarter() { + override fun execute(state: RunProfileState, env: ExecutionEnvironment) = starter(state, env) +} + +internal fun executeState(state: RunProfileState, env: ExecutionEnvironment, runner: ProgramRunner<*>): RunContentDescriptor? { + FileDocumentManager.getInstance().saveAllDocuments() + return showRunContent(state.execute(env.executor, runner), env) +} + +fun showRunContent(executionResult: ExecutionResult?, environment: ExecutionEnvironment): RunContentDescriptor? { + return executionResult?.let { RunContentBuilder(it, environment).showRunContent(environment.contentToReuse) } +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunnerImpl.kt b/platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunnerImpl.kt index 87e1cc0742c9..5c242f790500 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunnerImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/runners/DefaultProgramRunnerImpl.kt @@ -20,8 +20,6 @@ import com.intellij.execution.configurations.RunProfile import com.intellij.execution.configurations.RunProfileState import com.intellij.execution.configurations.RunnerSettings import com.intellij.execution.executors.DefaultRunExecutor -import com.intellij.execution.ui.RunContentDescriptor -import com.intellij.openapi.fileEditor.FileDocumentManager import org.jetbrains.concurrency.Promise import org.jetbrains.concurrency.resolvedPromise @@ -44,14 +42,4 @@ private class DefaultProgramRunnerImpl : AsyncGenericProgramRunner RunContentDescriptor?) = object : RunProfileStarter() { - override fun execute(state: RunProfileState, env: ExecutionEnvironment) = starter(state, env) -} - -internal fun executeState(state: RunProfileState, env: ExecutionEnvironment, runner: ProgramRunner<*>): RunContentDescriptor? { - FileDocumentManager.getInstance().saveAllDocuments() - val executionResult = state.execute(env.executor, runner) ?: return null - return RunContentBuilder(executionResult, env).showRunContent(env.contentToReuse) } \ No newline at end of file diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunner.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunner.java index 2017cf5ca350..703ec600c292 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunner.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/run/XsltRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * 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. @@ -26,11 +26,13 @@ import org.jetbrains.annotations.NotNull; * Time: 19:59:57 */ public class XsltRunner extends DefaultProgramRunner { + @Override @NotNull public String getRunnerId() { return "XsltProgramRunner"; } + @Override public boolean canRun(@NotNull final String executorId, @NotNull final RunProfile profile) { return DefaultRunExecutor.EXECUTOR_ID.equals(executorId) && profile instanceof XsltRunConfiguration && diff --git a/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/XsltDebuggerRunner.java b/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/XsltDebuggerRunner.java index 59bc6a48ea9c..ab3da34d72a9 100644 --- a/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/XsltDebuggerRunner.java +++ b/plugins/xslt-debugger/src/org/intellij/plugins/xsltDebugger/XsltDebuggerRunner.java @@ -4,8 +4,8 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.ExecutionResult; import com.intellij.execution.configurations.RunProfile; import com.intellij.execution.configurations.RunProfileState; -import com.intellij.execution.runners.DefaultProgramRunner; import com.intellij.execution.runners.ExecutionEnvironment; +import com.intellij.execution.runners.GenericProgramRunner; import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.xdebugger.XDebugProcess; @@ -15,20 +15,15 @@ import com.intellij.xdebugger.XDebuggerManager; import org.intellij.lang.xpath.xslt.run.XsltCommandLineState; import org.intellij.lang.xpath.xslt.run.XsltRunConfiguration; import org.intellij.plugins.xsltDebugger.impl.XsltDebugProcess; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -public class XsltDebuggerRunner extends DefaultProgramRunner { +public class XsltDebuggerRunner extends GenericProgramRunner { static final ThreadLocal ACTIVE = new ThreadLocal<>(); - @NonNls - private static final String ID = "XsltDebuggerRunner"; - - @NotNull @Override public String getRunnerId() { - return ID; + return "XsltDebuggerRunner"; } @Override @@ -45,6 +40,7 @@ public class XsltDebuggerRunner extends DefaultProgramRunner { protected RunContentDescriptor createContentDescriptor(final RunProfileState runProfileState, final ExecutionEnvironment environment) throws ExecutionException { final XDebugSession debugSession = XDebuggerManager.getInstance(environment.getProject()).startSession(environment, new XDebugProcessStarter() { + @Override @NotNull public XDebugProcess start(@NotNull final XDebugSession session) throws ExecutionException { ACTIVE.set(Boolean.TRUE); diff --git a/python/src/com/jetbrains/python/run/PythonRunner.java b/python/src/com/jetbrains/python/run/PythonRunner.java index 8509b55bb531..29b1576d2dc0 100644 --- a/python/src/com/jetbrains/python/run/PythonRunner.java +++ b/python/src/com/jetbrains/python/run/PythonRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -20,9 +20,9 @@ import com.intellij.execution.ExecutionResult; import com.intellij.execution.configurations.RunProfile; import com.intellij.execution.configurations.RunProfileState; import com.intellij.execution.executors.DefaultRunExecutor; -import com.intellij.execution.runners.DefaultProgramRunner; +import com.intellij.execution.runners.DefaultProgramRunnerKt; import com.intellij.execution.runners.ExecutionEnvironment; -import com.intellij.execution.runners.RunContentBuilder; +import com.intellij.execution.runners.GenericProgramRunner; import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.openapi.fileEditor.FileDocumentManager; import org.jetbrains.annotations.NotNull; @@ -30,13 +30,14 @@ import org.jetbrains.annotations.NotNull; /** * @author yole */ -public class PythonRunner extends DefaultProgramRunner { - +public class PythonRunner extends GenericProgramRunner { + @Override @NotNull public String getRunnerId() { return "PythonRunner"; } + @Override public boolean canRun(@NotNull final String executorId, @NotNull final RunProfile profile) { return executorId.equals(DefaultRunExecutor.EXECUTOR_ID) && profile instanceof AbstractPythonRunConfiguration; } @@ -53,6 +54,6 @@ public class PythonRunner extends DefaultProgramRunner { else { executionResult = state.execute(env.getExecutor(), this); } - return executionResult == null ? null : new RunContentBuilder(executionResult, env).showRunContent(env.getContentToReuse()); + return DefaultProgramRunnerKt.showRunContent(executionResult, env); } }