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);
}
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);
}
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);
}
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);
}
Aggregations