mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract RunLineMarkerContributor.withExecutorActions
This commit is contained in:
@@ -1,23 +1,8 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// 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.testIntegration;
|
||||
|
||||
import com.intellij.codeInsight.TestFrameworks;
|
||||
import com.intellij.execution.TestStateStorage;
|
||||
import com.intellij.execution.lineMarker.ExecutorAction;
|
||||
import com.intellij.execution.lineMarker.RunLineMarkerContributor;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -27,8 +12,6 @@ import com.intellij.psi.util.ClassUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
@@ -56,8 +39,7 @@ public class TestRunLineMarkerProvider extends RunLineMarkerContributor {
|
||||
|
||||
@NotNull
|
||||
private static Info getInfo(TestStateStorage.Record state, boolean isClass) {
|
||||
Icon icon = getTestStateIcon(state, isClass);
|
||||
return new Info(icon, ExecutorAction.getActions(1), RunLineMarkerContributor.RUN_TEST_TOOLTIP_PROVIDER);
|
||||
return RunLineMarkerContributor.withExecutorActions(getTestStateIcon(state, isClass));
|
||||
}
|
||||
|
||||
protected boolean isIdentifier(PsiElement e) {
|
||||
|
||||
@@ -31,13 +31,17 @@ class ExecutorAction private constructor(private val origin: AnAction,
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun getActions(order: Int = 0): Array<AnAction> {
|
||||
fun getActions(order: Int = 0) = getActionList(order).toTypedArray()
|
||||
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun getActionList(order: Int = 0): List<AnAction> {
|
||||
val actionManager = ActionManager.getInstance()
|
||||
return ExecutorRegistry.getInstance().registeredExecutors
|
||||
.map { executor -> executor to actionManager.getAction(executor.contextActionId) }
|
||||
.filter { pair -> pair.second != null }
|
||||
.map { pair -> ExecutorAction(pair.second, pair.first, order) }
|
||||
.toTypedArray()
|
||||
.mapNotNull { executor ->
|
||||
val action = actionManager.getAction(executor.contextActionId) ?: return@mapNotNull null
|
||||
ExecutorAction(action, executor, order)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConfigurations(dataContext: DataContext): List<ConfigurationFromContext> {
|
||||
@@ -80,17 +84,17 @@ class ExecutorAction private constructor(private val origin: AnAction,
|
||||
origin.actionPerformed(e)
|
||||
}
|
||||
|
||||
override fun canBePerformed(context: DataContext): Boolean = origin !is ActionGroup || origin.canBePerformed(context)
|
||||
override fun canBePerformed(context: DataContext) = origin !is ActionGroup || origin.canBePerformed(context)
|
||||
|
||||
override fun getChildren(e: AnActionEvent?): Array<AnAction> = (origin as? ActionGroup)?.getChildren(e) ?: AnAction.EMPTY_ARRAY
|
||||
override fun getChildren(e: AnActionEvent?) = (origin as? ActionGroup)?.getChildren(e) ?: AnAction.EMPTY_ARRAY
|
||||
|
||||
override fun isDumbAware(): Boolean = origin.isDumbAware
|
||||
override fun isDumbAware() = origin.isDumbAware
|
||||
|
||||
override fun isPopup(): Boolean = origin !is ActionGroup || origin.isPopup
|
||||
override fun isPopup() = origin !is ActionGroup || origin.isPopup
|
||||
|
||||
override fun hideIfNoVisibleChildren(): Boolean = origin is ActionGroup && origin.hideIfNoVisibleChildren()
|
||||
override fun hideIfNoVisibleChildren() = origin is ActionGroup && origin.hideIfNoVisibleChildren()
|
||||
|
||||
override fun disableIfNoVisibleChildren(): Boolean = origin !is ActionGroup || origin.disableIfNoVisibleChildren()
|
||||
override fun disableIfNoVisibleChildren() = origin !is ActionGroup || origin.disableIfNoVisibleChildren()
|
||||
|
||||
fun getActionName(dataContext: DataContext): String? {
|
||||
val list = getConfigurations(dataContext)
|
||||
|
||||
+10
-18
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.execution.lineMarker;
|
||||
|
||||
import com.intellij.execution.TestStateStorage;
|
||||
@@ -36,6 +22,11 @@ public abstract class RunLineMarkerContributor {
|
||||
|
||||
static final LanguageExtension<RunLineMarkerContributor> EXTENSION = new LanguageExtension<>("com.intellij.runLineMarkerContributor");
|
||||
|
||||
@NotNull
|
||||
public static Info withExecutorActions(@NotNull Icon icon) {
|
||||
return new Info(icon, ExecutorAction.getActions(1), RUN_TEST_TOOLTIP_PROVIDER);
|
||||
}
|
||||
|
||||
public static class Info {
|
||||
public final Icon icon;
|
||||
public final AnAction[] actions;
|
||||
@@ -76,11 +67,12 @@ public abstract class RunLineMarkerContributor {
|
||||
return action instanceof ExecutorAction ? ((ExecutorAction)action).getActionName(dataContext) : null;
|
||||
}
|
||||
|
||||
protected static Icon getTestStateIcon(String url, Project project, boolean isClass) {
|
||||
TestStateStorage.Record state = TestStateStorage.getInstance(project).getState(url);
|
||||
return getTestStateIcon(state, isClass);
|
||||
@NotNull
|
||||
protected static Icon getTestStateIcon(String url, @NotNull Project project, boolean isClass) {
|
||||
return getTestStateIcon(TestStateStorage.getInstance(project).getState(url), isClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static Icon getTestStateIcon(@Nullable TestStateStorage.Record state, boolean isClass) {
|
||||
if (state != null) {
|
||||
TestStateInfo.Magnitude magnitude = TestIconMapper.getMagnitude(state.magnitude);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// 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.jetbrains.python.testing
|
||||
|
||||
import com.intellij.execution.lineMarker.ExecutorAction
|
||||
import com.intellij.execution.lineMarker.RunLineMarkerContributor
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -15,7 +14,6 @@ import com.jetbrains.python.psi.types.TypeEvalContext
|
||||
|
||||
object PyTestLineMarkerContributor : RunLineMarkerContributor() {
|
||||
override fun getInfo(element: PsiElement): Info? {
|
||||
|
||||
if ((element !is LeafPsiElement) || element.elementType != PyTokenTypes.IDENTIFIER) {
|
||||
return null
|
||||
}
|
||||
@@ -25,11 +23,7 @@ object PyTestLineMarkerContributor : RunLineMarkerContributor() {
|
||||
if ((testElement is PyClass || testElement is PyFunction)
|
||||
&& (testElement is PsiNamedElement)
|
||||
&& isTestElement(testElement, ThreeState.UNSURE, typeEvalContext)) {
|
||||
|
||||
return RunLineMarkerContributor.Info(
|
||||
AllIcons.RunConfigurations.TestState.Run,
|
||||
ExecutorAction.getActions(1),
|
||||
RunLineMarkerContributor.RUN_TEST_TOOLTIP_PROVIDER)
|
||||
return RunLineMarkerContributor.withExecutorActions(AllIcons.RunConfigurations.TestState.Run)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user