Search in sources :

Example 36 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext 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 37 with ConfigurationFromContext

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

the class GroovyScriptRunConfigurationProducer method createConfigurationByElement.

@Override
protected RunnerAndConfigurationSettings createConfigurationByElement(final Location location, final ConfigurationContext context) {
    final PsiElement element = location.getPsiElement();
    final PsiFile file = element.getContainingFile();
    if (!(file instanceof GroovyFile)) {
        return null;
    }
    GroovyFile groovyFile = (GroovyFile) file;
    final PsiClass aClass = GroovyRunnerPsiUtil.getRunningClass(location.getPsiElement());
    if (aClass instanceof GroovyScriptClass || GroovyRunnerPsiUtil.isRunnable(aClass)) {
        final RunnerAndConfigurationSettings settings = createConfiguration(aClass);
        if (settings != null) {
            mySourceElement = element;
            final GroovyScriptRunConfiguration configuration = (GroovyScriptRunConfiguration) settings.getConfiguration();
            GroovyScriptUtil.getScriptType(groovyFile).tuneConfiguration(groovyFile, configuration, location);
            return settings;
        }
    }
    if (file.getText().contains("@Grab")) {
        ApplicationConfigurationProducer producer = new ApplicationConfigurationProducer();
        ConfigurationFromContext settings = producer.createConfigurationFromContext(context);
        if (settings != null) {
            PsiElement src = settings.getSourceElement();
            mySourceElement = src;
            return createConfiguration(src instanceof PsiMethod ? ((PsiMethod) src).getContainingClass() : (PsiClass) src);
        }
        return null;
    } else {
        return null;
    }
}
Also used : GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) ApplicationConfigurationProducer(com.intellij.execution.application.ApplicationConfigurationProducer) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Example 38 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project ballerina by ballerina-lang.

the class BallerinaRunConfigurationProducerTest method testServiceWithPackageRunConfigurationFromContext.

public void testServiceWithPackageRunConfigurationFromContext() {
    PsiFile file = myFixture.addFileToProject("org/test/a.bal", "package org.test;\nservice<http> <caret>main {}");
    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
    PsiElement element = file.findElementAt(myFixture.getCaretOffset());
    assertNotNull(element);
    ConfigurationContext configurationContext = new ConfigurationContext(element);
    BallerinaApplicationRunConfigurationProducer producer = new BallerinaApplicationRunConfigurationProducer();
    ConfigurationFromContext configurationFromContext = producer.createConfigurationFromContext(configurationContext);
    assertNotNull(configurationFromContext);
    RunConfiguration runConfiguration = configurationFromContext.getConfiguration();
    assertTrue(runConfiguration instanceof BallerinaApplicationConfiguration);
    BallerinaApplicationConfiguration ballerinaApplicationConfiguration = (BallerinaApplicationConfiguration) runConfiguration;
    assertEquals(RunConfigurationKind.SERVICE, ballerinaApplicationConfiguration.getRunKind());
    assertEquals(file.getVirtualFile().getPath(), ballerinaApplicationConfiguration.getFilePath());
    assertEquals("org/test", ballerinaApplicationConfiguration.getPackage());
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) BallerinaApplicationRunConfigurationProducer(org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationRunConfigurationProducer) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) BallerinaApplicationConfiguration(org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationConfiguration)

Example 39 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project ballerina by ballerina-lang.

the class BallerinaRunConfigurationProducerTest method testMainWithPackageRunConfigurationFromContext.

public void testMainWithPackageRunConfigurationFromContext() {
    PsiFile file = myFixture.addFileToProject("org/test/a.bal", "package org.test;\nfunction <caret>main() {}");
    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
    PsiElement element = file.findElementAt(myFixture.getCaretOffset());
    assertNotNull(element);
    ConfigurationContext configurationContext = new ConfigurationContext(element);
    BallerinaApplicationRunConfigurationProducer producer = new BallerinaApplicationRunConfigurationProducer();
    ConfigurationFromContext configurationFromContext = producer.createConfigurationFromContext(configurationContext);
    assertNotNull(configurationFromContext);
    RunConfiguration runConfiguration = configurationFromContext.getConfiguration();
    assertTrue(runConfiguration instanceof BallerinaApplicationConfiguration);
    BallerinaApplicationConfiguration ballerinaApplicationConfiguration = (BallerinaApplicationConfiguration) runConfiguration;
    assertEquals(RunConfigurationKind.MAIN, ballerinaApplicationConfiguration.getRunKind());
    assertEquals(file.getVirtualFile().getPath(), ballerinaApplicationConfiguration.getFilePath());
    assertEquals("org/test", ballerinaApplicationConfiguration.getPackage());
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) BallerinaApplicationRunConfigurationProducer(org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationRunConfigurationProducer) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) BallerinaApplicationConfiguration(org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationConfiguration)

Example 40 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project ballerina by ballerina-lang.

the class BallerinaRunConfigurationProducerTest method testServiceWithoutPackageRunConfigurationFromContext.

public void testServiceWithoutPackageRunConfigurationFromContext() {
    PsiFile file = myFixture.configureByText("a.bal", "service<http> <caret>main {}");
    PsiElement element = file.findElementAt(myFixture.getCaretOffset());
    assertNotNull(element);
    ConfigurationContext configurationContext = new ConfigurationContext(element);
    BallerinaApplicationRunConfigurationProducer producer = new BallerinaApplicationRunConfigurationProducer();
    ConfigurationFromContext configurationFromContext = producer.createConfigurationFromContext(configurationContext);
    assertNotNull(configurationFromContext);
    RunConfiguration runConfiguration = configurationFromContext.getConfiguration();
    assertTrue(runConfiguration instanceof BallerinaApplicationConfiguration);
    BallerinaApplicationConfiguration ballerinaApplicationConfiguration = (BallerinaApplicationConfiguration) runConfiguration;
    assertEquals(RunConfigurationKind.SERVICE, ballerinaApplicationConfiguration.getRunKind());
    assertEquals(file.getVirtualFile().getPath(), ballerinaApplicationConfiguration.getFilePath());
    assertEmpty(ballerinaApplicationConfiguration.getPackage());
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) BallerinaApplicationRunConfigurationProducer(org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationRunConfigurationProducer) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) BallerinaApplicationConfiguration(org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationConfiguration)

Aggregations

ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)76 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)69 Test (org.junit.Test)61 PsiFile (com.intellij.psi.PsiFile)56 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)54 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)50 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)38 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)38 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)13 PsiClass (com.intellij.psi.PsiClass)13 PsiDirectory (com.intellij.psi.PsiDirectory)10 PyFunction (com.jetbrains.python.psi.PyFunction)8 PsiElement (com.intellij.psi.PsiElement)6 TestContextRunConfigurationProducer (com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer)4 DataContext (com.intellij.openapi.actionSystem.DataContext)4 Project (com.intellij.openapi.project.Project)4 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)3 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)3 BallerinaApplicationConfiguration (org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationConfiguration)3 BallerinaApplicationRunConfigurationProducer (org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationRunConfigurationProducer)3