Search in sources :

Example 6 with ConfigurationContext

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);
    }
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) IdeaTestApplication(com.intellij.idea.IdeaTestApplication) TestDataProvider(com.intellij.testFramework.TestDataProvider) PsiElement(com.intellij.psi.PsiElement)

Example 7 with ConfigurationContext

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;
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext)

Example 8 with ConfigurationContext

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;
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) JBList(com.intellij.ui.components.JBList) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Arrays(java.util.Arrays) ArrayUtil(com.intellij.util.ArrayUtil) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) Document(com.intellij.openapi.editor.Document) FileEditor(com.intellij.openapi.fileEditor.FileEditor) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) List(java.util.List) PlatformDataKeys(com.intellij.openapi.actionSystem.PlatformDataKeys) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) PsiClassListCellRenderer(com.intellij.ide.util.PsiClassListCellRenderer) PsiClassUtil(com.intellij.psi.util.PsiClassUtil) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) com.intellij.psi(com.intellij.psi) ClassInheritorsSearch(com.intellij.psi.search.searches.ClassInheritorsSearch) Location(com.intellij.execution.Location) Collections(java.util.Collections) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) FileEditor(com.intellij.openapi.fileEditor.FileEditor) ArrayList(java.util.ArrayList) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) Document(com.intellij.openapi.editor.Document) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) TextEditor(com.intellij.openapi.fileEditor.TextEditor) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) PsiClassListCellRenderer(com.intellij.ide.util.PsiClassListCellRenderer) JBList(com.intellij.ui.components.JBList) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Example 9 with ConfigurationContext

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;
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ArrayList(java.util.ArrayList) CfmlRunConfiguration(com.intellij.coldFusion.UI.runner.CfmlRunConfiguration) Project(com.intellij.openapi.project.Project) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) CfmlRunConfiguration(com.intellij.coldFusion.UI.runner.CfmlRunConfiguration) RunConfigurationProducer(com.intellij.execution.actions.RunConfigurationProducer) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) Editor(com.intellij.openapi.editor.Editor)

Example 10 with ConfigurationContext

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);
}
Also used : Project(com.intellij.openapi.project.Project) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) DataContext(com.intellij.openapi.actionSystem.DataContext) JstdRunConfigurationProducer(com.google.jstestdriver.idea.execution.JstdRunConfigurationProducer) RunConfigurationProducer(com.intellij.execution.actions.RunConfigurationProducer) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) Editor(com.intellij.openapi.editor.Editor)

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