Search in sources :

Example 1 with InheritorChooser

use of com.intellij.execution.junit.InheritorChooser in project intellij-community by JetBrains.

the class AbstractInClassConfigurationProducer method onFirstRun.

public void onFirstRun(@NotNull final ConfigurationFromContext configuration, @NotNull final ConfigurationContext fromContext, @NotNull Runnable performRunnable) {
    final PsiElement psiElement = configuration.getSourceElement();
    if (psiElement instanceof PsiMethod || psiElement instanceof PsiClass) {
        final PsiMethod psiMethod;
        final PsiClass containingClass;
        if (psiElement instanceof PsiMethod) {
            psiMethod = (PsiMethod) psiElement;
            containingClass = psiMethod.getContainingClass();
        } else {
            psiMethod = null;
            containingClass = (PsiClass) psiElement;
        }
        final InheritorChooser inheritorChooser = new InheritorChooser() {

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

            @Override
            protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
                if (psiElement instanceof PsiMethod) {
                    final Project project = psiMethod.getProject();
                    final MethodLocation methodLocation = new MethodLocation(project, psiMethod, PsiLocation.fromPsiElement(aClass));
                    ((T) configuration.getConfiguration()).beMethodConfiguration(methodLocation);
                } else {
                    ((T) configuration.getConfiguration()).beClassConfiguration(aClass);
                }
                super.runForClass(aClass, psiMethod, context, performRunnable);
            }
        };
        if (inheritorChooser.runMethodInAbstractClass(fromContext, performRunnable, psiMethod, containingClass, aClass -> aClass.hasModifierProperty(PsiModifier.ABSTRACT) && isTestClass(aClass))) {
            return;
        }
    }
    super.onFirstRun(configuration, fromContext, performRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) Project(com.intellij.openapi.project.Project) InheritorChooser(com.intellij.execution.junit.InheritorChooser) List(java.util.List) MethodLocation(com.intellij.execution.junit2.info.MethodLocation)

Example 2 with InheritorChooser

use of com.intellij.execution.junit.InheritorChooser in project intellij-community by JetBrains.

the class TestClassGradleConfigurationProducer method onFirstRun.

@Override
public void onFirstRun(final ConfigurationFromContext fromContext, final ConfigurationContext context, @NotNull final Runnable performRunnable) {
    final InheritorChooser inheritorChooser = new InheritorChooser() {

        @Override
        protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestConfiguration(configuration, context, ArrayUtil.toObjectArray(classes, PsiClass.class)))
                return;
            super.runForClasses(classes, method, context, performRunnable);
        }

        @Override
        protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestConfiguration(configuration, context, aClass))
                return;
            super.runForClass(aClass, psiMethod, context, performRunnable);
        }
    };
    if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, null, (PsiClass) fromContext.getSourceElement()))
        return;
    super.onFirstRun(fromContext, context, performRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) InheritorChooser(com.intellij.execution.junit.InheritorChooser) List(java.util.List)

Example 3 with InheritorChooser

use of com.intellij.execution.junit.InheritorChooser in project intellij-community by JetBrains.

the class TestMethodGradleConfigurationProducer method onFirstRun.

@Override
public void onFirstRun(final ConfigurationFromContext fromContext, final ConfigurationContext context, @NotNull final Runnable performRunnable) {
    final PsiMethod psiMethod = (PsiMethod) fromContext.getSourceElement();
    final PsiClass containingClass = psiMethod.getContainingClass();
    final InheritorChooser inheritorChooser = new InheritorChooser() {

        @Override
        protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestMethodConfiguration(configuration, context, psiMethod, ArrayUtil.toObjectArray(classes, PsiClass.class)))
                return;
            super.runForClasses(classes, method, context, performRunnable);
        }

        @Override
        protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestMethodConfiguration(configuration, context, psiMethod, aClass))
                return;
            super.runForClass(aClass, psiMethod, context, performRunnable);
        }
    };
    if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, psiMethod, containingClass))
        return;
    super.onFirstRun(fromContext, context, performRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) InheritorChooser(com.intellij.execution.junit.InheritorChooser) List(java.util.List)

Example 4 with InheritorChooser

use of com.intellij.execution.junit.InheritorChooser 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)

Aggregations

ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)4 InheritorChooser (com.intellij.execution.junit.InheritorChooser)4 List (java.util.List)4 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)2 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)2 Project (com.intellij.openapi.project.Project)2 PsiClass (com.intellij.psi.PsiClass)2 PsiMethod (com.intellij.psi.PsiMethod)2 TestNGConfiguration (com.theoryinpractice.testng.configuration.TestNGConfiguration)1