Search in sources :

Example 16 with ConfigurationContext

use of com.intellij.execution.actions.ConfigurationContext in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRunConfigurationProducerTest method testSameRunFileConfigurationOnFile.

public void testSameRunFileConfigurationOnFile() {
    PsiFile file = myFixture.configureByText("a.go", "package main; <caret>\nfunc main() {}");
    PsiElement at = file.findElementAt(myFixture.getCaretOffset());
    assertNotNull(at);
    ConfigurationContext configurationContext = new ConfigurationContext(at);
    GoRunFileConfigurationProducer producer = new GoRunFileConfigurationProducer();
    GoRunFileConfiguration runConfiguration = createFileConfiguration(file.getVirtualFile().getPath());
    assertTrue(producer.isConfigurationFromContext(runConfiguration, configurationContext));
    runConfiguration = createFileConfiguration(file.getVirtualFile().getPath() + "_vl");
    assertFalse(producer.isConfigurationFromContext(runConfiguration, configurationContext));
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) GoRunFileConfigurationProducer(com.goide.runconfig.file.GoRunFileConfigurationProducer) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) GoRunFileConfiguration(com.goide.runconfig.file.GoRunFileConfiguration)

Example 17 with ConfigurationContext

use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.

the class AbstractInClassConfigurationProducer method onFirstRun.

public void onFirstRun(@NotNull final ConfigurationFromContext configuration, @NotNull final ConfigurationContext fromContext, @NotNull Runnable performRunnable) {
    final PsiElement psiElement = configuration.getSourceElement();
    if (psiElement instanceof PsiMethod || psiElement instanceof PsiClass) {
        final PsiMethod psiMethod;
        final PsiClass containingClass;
        if (psiElement instanceof PsiMethod) {
            psiMethod = (PsiMethod) psiElement;
            containingClass = psiMethod.getContainingClass();
        } else {
            psiMethod = null;
            containingClass = (PsiClass) psiElement;
        }
        final InheritorChooser inheritorChooser = new InheritorChooser() {

            @Override
            protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
                ((T) configuration.getConfiguration()).bePatternConfiguration(classes, method);
                super.runForClasses(classes, method, context, performRunnable);
            }

            @Override
            protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
                if (psiElement instanceof PsiMethod) {
                    final Project project = psiMethod.getProject();
                    final MethodLocation methodLocation = new MethodLocation(project, psiMethod, PsiLocation.fromPsiElement(aClass));
                    ((T) configuration.getConfiguration()).beMethodConfiguration(methodLocation);
                } else {
                    ((T) configuration.getConfiguration()).beClassConfiguration(aClass);
                }
                super.runForClass(aClass, psiMethod, context, performRunnable);
            }
        };
        if (inheritorChooser.runMethodInAbstractClass(fromContext, performRunnable, psiMethod, containingClass, aClass -> aClass.hasModifierProperty(PsiModifier.ABSTRACT) && isTestClass(aClass))) {
            return;
        }
    }
    super.onFirstRun(configuration, fromContext, performRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) Project(com.intellij.openapi.project.Project) InheritorChooser(com.intellij.execution.junit.InheritorChooser) List(java.util.List) MethodLocation(com.intellij.execution.junit2.info.MethodLocation)

Example 18 with ConfigurationContext

use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.

the class BaseConfigurationTestCase method createJUnitConfiguration.

protected JUnitConfiguration createJUnitConfiguration(@NotNull PsiElement psiElement, @NotNull Class<? extends AbstractJavaTestConfigurationProducer> producerClass, @NotNull MapDataContext dataContext) {
    ConfigurationContext context = createContext(psiElement, dataContext);
    RunConfigurationProducer producer = RunConfigurationProducer.getInstance(producerClass);
    assert producer != null;
    ConfigurationFromContext fromContext = producer.createConfigurationFromContext(context);
    assertNotNull(fromContext);
    return (JUnitConfiguration) fromContext.getConfiguration();
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) RunConfigurationProducer(com.intellij.execution.actions.RunConfigurationProducer) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration)

Example 19 with ConfigurationContext

use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.

the class RunExternalSystemTaskAction method perform.

@Override
protected void perform(@NotNull Project project, @NotNull ProjectSystemId projectSystemId, @NotNull TaskData taskData, @NotNull AnActionEvent e) {
    final ExternalTaskExecutionInfo taskExecutionInfo = ExternalSystemActionUtil.buildTaskInfo(taskData);
    ExternalSystemUtil.runTask(taskExecutionInfo.getSettings(), taskExecutionInfo.getExecutorId(), project, projectSystemId);
    final DataContext dataContext = e.getDataContext();
    final ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
    RunnerAndConfigurationSettings configuration = context.findExisting();
    RunManagerEx runManager = (RunManagerEx) context.getRunManager();
    if (configuration == null) {
        configuration = context.getConfiguration();
        if (configuration == null) {
            return;
        }
        runManager.setTemporaryConfiguration(configuration);
    }
    runManager.setSelectedConfiguration(configuration);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) DataContext(com.intellij.openapi.actionSystem.DataContext) RunManagerEx(com.intellij.execution.RunManagerEx) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings)

Example 20 with ConfigurationContext

use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.

the class TestClassGradleConfigurationProducer method onFirstRun.

@Override
public void onFirstRun(final ConfigurationFromContext fromContext, final ConfigurationContext context, @NotNull final Runnable performRunnable) {
    final InheritorChooser inheritorChooser = new InheritorChooser() {

        @Override
        protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestConfiguration(configuration, context, ArrayUtil.toObjectArray(classes, PsiClass.class)))
                return;
            super.runForClasses(classes, method, context, performRunnable);
        }

        @Override
        protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestConfiguration(configuration, context, aClass))
                return;
            super.runForClass(aClass, psiMethod, context, performRunnable);
        }
    };
    if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, null, (PsiClass) fromContext.getSourceElement()))
        return;
    super.onFirstRun(fromContext, context, performRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) InheritorChooser(com.intellij.execution.junit.InheritorChooser) List(java.util.List)

Aggregations

ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)26 PsiFile (com.intellij.psi.PsiFile)9 PsiElement (com.intellij.psi.PsiElement)7 GotestRunConfigurationProducer (com.goide.runconfig.testing.frameworks.gotest.GotestRunConfigurationProducer)5 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)5 InheritorChooser (com.intellij.execution.junit.InheritorChooser)5 List (java.util.List)5 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)4 Project (com.intellij.openapi.project.Project)4 Location (com.intellij.execution.Location)3 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)3 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)3 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)3 PsiClass (com.intellij.psi.PsiClass)3 PsiMethod (com.intellij.psi.PsiMethod)3 GoApplicationConfiguration (com.goide.runconfig.application.GoApplicationConfiguration)2 GoApplicationRunConfigurationProducer (com.goide.runconfig.application.GoApplicationRunConfigurationProducer)2 GoRunFileConfiguration (com.goide.runconfig.file.GoRunFileConfiguration)2 GoRunFileConfigurationProducer (com.goide.runconfig.file.GoRunFileConfigurationProducer)2