Search in sources :

Example 6 with MethodLocation

use of com.intellij.execution.junit2.info.MethodLocation in project kotlin by JetBrains.

the class KotlinTestNgConfigurationProducer method onFirstRun.

@Override
public void onFirstRun(ConfigurationFromContext configuration, ConfigurationContext context, Runnable startRunnable) {
    KtNamedDeclaration declarationToRun = getDeclarationToRun(configuration.getSourceElement());
    final PsiNamedElement lightElement = CollectionsKt.firstOrNull(LightClassUtilsKt.toLightElements(declarationToRun));
    // Copied from TestNGInClassConfigurationProducer.onFirstRun()
    if (lightElement instanceof PsiMethod || lightElement instanceof PsiClass) {
        PsiMethod psiMethod;
        PsiClass containingClass;
        if (lightElement instanceof PsiMethod) {
            psiMethod = (PsiMethod) lightElement;
            containingClass = psiMethod.getContainingClass();
        } else {
            psiMethod = null;
            containingClass = (PsiClass) lightElement;
        }
        InheritorChooser inheritorChooser = new InheritorChooser() {

            @Override
            protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
                ((TestNGConfiguration) context.getConfiguration().getConfiguration()).bePatternConfiguration(classes, method);
                super.runForClasses(classes, method, context, performRunnable);
            }

            @Override
            protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
                if (lightElement instanceof PsiMethod) {
                    Project project = psiMethod.getProject();
                    MethodLocation methodLocation = new MethodLocation(project, psiMethod, PsiLocation.fromPsiElement(aClass));
                    ((TestNGConfiguration) context.getConfiguration().getConfiguration()).setMethodConfiguration(methodLocation);
                } else {
                    ((TestNGConfiguration) context.getConfiguration().getConfiguration()).setClassConfiguration(aClass);
                }
                super.runForClass(aClass, psiMethod, context, performRunnable);
            }
        };
        if (inheritorChooser.runMethodInAbstractClass(context, startRunnable, psiMethod, containingClass, new Condition<PsiClass>() {

            @Override
            public boolean value(PsiClass aClass) {
                return aClass.hasModifierProperty(PsiModifier.ABSTRACT) && TestNGUtil.hasTest(aClass);
            }
        }))
            return;
    }
    super.onFirstRun(configuration, context, startRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) TestNGConfiguration(com.theoryinpractice.testng.configuration.TestNGConfiguration) InheritorChooser(com.intellij.execution.junit.InheritorChooser) Project(com.intellij.openapi.project.Project) List(java.util.List) MethodLocation(com.intellij.execution.junit2.info.MethodLocation)

Example 7 with MethodLocation

use of com.intellij.execution.junit2.info.MethodLocation in project android by JetBrains.

the class TestMethodAndroidConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(JUnitConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
        return false;
    }
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    Location<PsiMethod> methodLocation = getTestMethod(contextLocation);
    if (methodLocation == null)
        return false;
    if (contextLocation instanceof PsiMemberParameterizedLocation) {
        final String paramSetName = ((PsiMemberParameterizedLocation) contextLocation).getParamSetName();
        if (paramSetName != null) {
            configuration.setProgramParameters(paramSetName);
        }
        PsiClass containingClass = ((PsiMemberParameterizedLocation) contextLocation).getContainingClass();
        if (containingClass != null) {
            methodLocation = MethodLocation.elementInClass(methodLocation.getPsiElement(), containingClass);
        }
    }
    sourceElement.set(methodLocation.getPsiElement());
    setupConfigurationModule(context, configuration);
    final Module originalModule = configuration.getConfigurationModule().getModule();
    configuration.beMethodConfiguration(methodLocation);
    configuration.restoreOriginalModule(originalModule);
    JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, contextLocation);
    configuration.setForkMode(JUnitConfiguration.FORK_NONE);
    return true;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation)

Aggregations

MethodLocation (com.intellij.execution.junit2.info.MethodLocation)7 Location (com.intellij.execution.Location)4 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)3 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)3 Project (com.intellij.openapi.project.Project)3 PsiMethod (com.intellij.psi.PsiMethod)3 List (java.util.List)3 InheritorChooser (com.intellij.execution.junit.InheritorChooser)2 Module (com.intellij.openapi.module.Module)2 PsiClass (com.intellij.psi.PsiClass)2 PsiLocation (com.intellij.execution.PsiLocation)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 PsiClassListCellRenderer (com.intellij.ide.util.PsiClassListCellRenderer)1 PlatformDataKeys (com.intellij.openapi.actionSystem.PlatformDataKeys)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Document (com.intellij.openapi.editor.Document)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)1