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();
}
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;
}
}
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());
}
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());
}
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());
}
Aggregations