use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.
the class JUnitRerunFailedTestsTest method testMultipleClassesInOneFile.
public void testMultipleClassesInOneFile() throws Exception {
myFixture.configureByText("a.java", "public class Test1 {<caret>} public class Test2 {}");
final IdeaTestApplication testApplication = IdeaTestApplication.getInstance();
try {
testApplication.setDataProvider(new TestDataProvider(myFixture.getProject()) {
@Override
public Object getData(@NonNls String dataId) {
if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
return new VirtualFile[] { myFixture.getFile().getVirtualFile() };
}
return super.getData(dataId);
}
});
final PsiElement psiElement = myFixture.getFile().findElementAt(getEditor().getCaretModel().getOffset());
final PatternConfigurationProducer configurationProducer = RunConfigurationProducer.getInstance(PatternConfigurationProducer.class);
assertFalse(configurationProducer.isMultipleElementsSelected(new ConfigurationContext(psiElement)));
} finally {
testApplication.setDataProvider(null);
}
}
use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.
the class BaseConfigurationTestCase method createConfiguration.
protected <T extends RunConfiguration> T createConfiguration(@NotNull PsiElement psiElement, @NotNull MapDataContext dataContext) {
ConfigurationContext context = createContext(psiElement, dataContext);
RunnerAndConfigurationSettings settings = context.getConfiguration();
@SuppressWarnings("unchecked") T configuration = settings == null ? null : (T) settings.getConfiguration();
return configuration;
}
use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.
the class InheritorChooser method runMethodInAbstractClass.
public boolean runMethodInAbstractClass(final ConfigurationContext context, final Runnable performRunnable, final PsiMethod psiMethod, final PsiClass containingClass, final Condition<PsiClass> acceptAbstractCondition) {
if (containingClass != null && acceptAbstractCondition.value(containingClass)) {
final Location location = context.getLocation();
if (location instanceof MethodLocation) {
final PsiClass aClass = ((MethodLocation) location).getContainingClass();
if (aClass != null && !aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
return false;
}
} else if (location instanceof PsiMemberParameterizedLocation) {
return false;
}
final List<PsiClass> classes = new ArrayList<>();
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
final boolean isJUnit5 = ReadAction.compute(() -> JUnitUtil.isJUnit5(containingClass));
ClassInheritorsSearch.search(containingClass).forEach(aClass -> {
if (isJUnit5 && JUnitUtil.isJUnit5TestClass(aClass, true) || PsiClassUtil.isRunnableClass(aClass, true, true)) {
classes.add(aClass);
}
return true;
});
}, "Search for " + containingClass.getQualifiedName() + " inheritors", true, containingClass.getProject())) {
return true;
}
if (classes.size() == 1) {
runForClass(classes.get(0), psiMethod, context, performRunnable);
return true;
}
if (classes.isEmpty())
return false;
final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(context.getDataContext());
if (fileEditor instanceof TextEditor) {
final Document document = ((TextEditor) fileEditor).getEditor().getDocument();
final PsiFile containingFile = PsiDocumentManager.getInstance(context.getProject()).getPsiFile(document);
if (containingFile instanceof PsiClassOwner) {
final List<PsiClass> psiClasses = new ArrayList<>(Arrays.asList(((PsiClassOwner) containingFile).getClasses()));
psiClasses.retainAll(classes);
if (psiClasses.size() == 1) {
runForClass(psiClasses.get(0), psiMethod, context, performRunnable);
return true;
}
}
}
final int numberOfInheritors = classes.size();
final PsiClassListCellRenderer renderer = new PsiClassListCellRenderer() {
@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value == null) {
renderer.append("All (" + numberOfInheritors + ")");
return true;
}
return super.customizeNonPsiElementLeftRenderer(renderer, list, value, index, selected, hasFocus);
}
};
Collections.sort(classes, renderer.getComparator());
//suggest to run all inherited tests
classes.add(0, null);
final JBList list = new JBList(classes);
list.setCellRenderer(renderer);
JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose executable classes to run " + (psiMethod != null ? psiMethod.getName() : containingClass.getName())).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
final Object[] values = list.getSelectedValues();
if (values == null)
return;
chooseAndPerform(values, psiMethod, context, performRunnable, classes);
}).createPopup().showInBestPositionFor(context.getDataContext());
return true;
}
return false;
}
use of com.intellij.execution.actions.ConfigurationContext in project intellij-plugins by JetBrains.
the class CfmlRunConfigurationTest method getDefaultCfmlRunConfiguration.
public CfmlRunConfiguration getDefaultCfmlRunConfiguration() throws IOException {
final Project project = myFixture.getProject();
final Editor editor = openCfmFileInEditor(indexCfm);
final Presentation presentation = getPresentationForRunAction(editor);
assert editor != null;
final DataContext dataContext = DataManager.getInstance().getDataContext(editor.getComponent());
TestCase.assertEquals("Run 'index.cfm'", presentation.getText());
final ConfigurationContext configurationContext = ConfigurationContext.getFromContext(dataContext);
final List<RunConfigurationProducer<?>> producers = RunConfigurationProducer.getProducers(project);
List<ConfigurationFromContext> configs = new ArrayList<>();
for (RunConfigurationProducer<?> producer : producers) {
final ConfigurationFromContext configurationFromContext = producer.createConfigurationFromContext(configurationContext);
if (configurationFromContext != null)
configs.add(configurationFromContext);
}
TestCase.assertEquals(true, configs.size() == 1);
final ConfigurationFromContext defaultConfigurationFromContext = configs.get(0);
final RunConfiguration configuration = defaultConfigurationFromContext.getConfiguration();
TestCase.assertNotNull(configuration);
UsefulTestCase.assertInstanceOf(configuration, CfmlRunConfiguration.class);
return (CfmlRunConfiguration) configuration;
}
use of com.intellij.execution.actions.ConfigurationContext in project intellij-plugins by JetBrains.
the class JstdAssertionFrameworkLineMarkerProvider method execute.
private static void execute(@NotNull Executor executor, @NotNull final PsiElement element) {
Project project = element.getProject();
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor == null) {
return;
}
DataContext dataContext = createDataContext(editor, element);
RunConfigurationProducer jstdOriginalProducer = getJstdRunConfigurationProducer();
ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
boolean created = false;
RunnerAndConfigurationSettings configuration = jstdOriginalProducer.findExistingConfiguration(context);
if (configuration == null) {
created = true;
ConfigurationFromContext fromContext = jstdOriginalProducer.createConfigurationFromContext(context);
if (fromContext != null) {
configuration = fromContext.getConfigurationSettings();
} else {
return;
}
}
execute(project, executor, configuration, created);
}
Aggregations