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