use of com.intellij.execution.actions.ConfigurationFromContext in project intellij-plugins by JetBrains.
the class FlexUnitConfigurationTest method doTest.
private void doTest(String filename) throws Exception {
configureByFile(BASE_PATH + filename);
final Map<Integer, String> markers = JSTestUtils.extractPositionMarkers(getProject(), getEditor().getDocument());
assertFalse("No caret markers found", markers.isEmpty());
assertFalse("No 'expected' value", markers.containsValue(null));
final DataContext dataContext = DataManager.getInstance().getDataContext(getEditor().getComponent());
int i = 1;
for (Map.Entry<Integer, String> marker : markers.entrySet()) {
String place = filename + ": marker " + i++ + ": ";
getEditor().getCaretModel().moveToOffset(marker.getKey());
final ConfigurationFromContext configurationFromContext = new FlexUnitRuntimeConfigurationProducer().createConfigurationFromContext(ConfigurationContext.getFromContext(dataContext));
final RunConfiguration configuration = configurationFromContext == null ? null : configurationFromContext.getConfiguration();
if ("null".equals(marker.getValue())) {
assertNull(place + "Null configuration expected", configuration);
} else {
assertNotNull(place + "Not null configuration expected", configuration);
assertTrue(place + "Invalid configuration", configuration instanceof FlexUnitRunConfiguration);
final String[] expected;
if ("null".equals(marker.getValue())) {
expected = null;
} else {
expected = marker.getValue().split(" ");
assertEquals(place + "Expected should be in the form: \"Class com.test.Foo\" or \"Method com.test.Foo.testBar()\" or \"Package com.test\"", 2, expected.length);
}
final FlexUnitRunnerParameters params = ((FlexUnitRunConfiguration) configuration).getRunnerParameters();
assertEquals(place + "Invalid scope", expected[0], params.getScope().name());
final String definition;
switch(params.getScope()) {
case Class:
definition = params.getClassName();
break;
case Method:
definition = params.getClassName() + "." + params.getMethodName() + "()";
break;
case Package:
definition = params.getPackageName();
break;
default:
fail(place + "Unknown scope: " + params.getScope());
definition = null;
}
assertEquals(place + "Invalid definition", expected[1], definition);
}
}
}
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;
}
}
Aggregations