use of com.intellij.execution.junit2.PsiMemberParameterizedLocation in project intellij-community by JetBrains.
the class TestMethods method getTestPresentation.
@Nullable
public static String getTestPresentation(AbstractTestProxy testInfo, Project project, GlobalSearchScope searchScope) {
final Location location = testInfo.getLocation(project, searchScope);
final PsiElement element = location != null ? location.getPsiElement() : null;
if (element instanceof PsiMethod) {
final PsiClass containingClass = location instanceof MethodLocation ? ((MethodLocation) location).getContainingClass() : location instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) location).getContainingClass() : ((PsiMethod) element).getContainingClass();
if (containingClass != null) {
final String proxyName = testInfo.getName();
final String methodName = ((PsiMethod) element).getName();
return JavaExecutionUtil.getRuntimeQualifiedName(containingClass) + "," + (proxyName.contains(methodName) ? proxyName.substring(proxyName.indexOf(methodName)) : methodName);
}
}
return null;
}
use of com.intellij.execution.junit2.PsiMemberParameterizedLocation 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;
}
use of com.intellij.execution.junit2.PsiMemberParameterizedLocation in project android by JetBrains.
the class TestPatternConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(AndroidJUnitConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
LinkedHashSet<String> classes = new LinkedHashSet<String>();
PsiElement element = checkPatterns(context, classes);
if (element == null) {
return false;
}
sourceElement.set(element);
JUnitConfiguration.Data data = configuration.getPersistentData();
data.setPatterns(classes);
data.TEST_OBJECT = JUnitConfiguration.TEST_PATTERN;
data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
configuration.setGeneratedName();
Location contextLocation = context.getLocation();
if (contextLocation instanceof PsiMemberParameterizedLocation) {
String paramSetName = ((PsiMemberParameterizedLocation) contextLocation).getParamSetName();
if (paramSetName != null) {
configuration.setProgramParameters(paramSetName);
}
}
return true;
}
use of com.intellij.execution.junit2.PsiMemberParameterizedLocation in project intellij-community by JetBrains.
the class JavaTestLocator method collectMethodNavigatables.
private static List<Location> collectMethodNavigatables(@NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope, String paramName) {
List<Location> results = Collections.emptyList();
String className = StringUtil.getPackageName(path);
if (!StringUtil.isEmpty(className)) {
String methodName = StringUtil.getShortName(path);
PsiClass aClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), className, null, true, scope);
if (aClass != null) {
results = ContainerUtil.newSmartList();
if (methodName.trim().equals(aClass.getName())) {
results.add(createClassNavigatable(paramName, aClass));
} else {
PsiMethod[] methods = aClass.findMethodsByName(methodName.trim(), true);
if (methods.length > 0) {
for (PsiMethod method : methods) {
results.add(paramName != null ? new PsiMemberParameterizedLocation(project, method, aClass, paramName) : MethodLocation.elementInClass(method, aClass));
}
}
}
}
}
return results;
}
use of com.intellij.execution.junit2.PsiMemberParameterizedLocation in project android by JetBrains.
the class AndroidJUnitConfigurations method isFromContext.
// Copy of JUnitConfigurationProducer#isConfigurationFromContext using AndroidJUnitConfigurationType instead of JUnitConfigurationType
public static boolean isFromContext(@NotNull JUnitConfiguration unitConfiguration, @NotNull ConfigurationContext context, @NotNull ConfigurationFactory configurationFactory) {
if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
return false;
}
RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(AndroidJUnitConfigurationType.getInstance());
Location contextLocation = context.getLocation();
String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName() : null;
assert contextLocation != null;
Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
if (location == null) {
return false;
}
PsiElement element = location.getPsiElement();
PsiClass testClass = getTestClass(element);
PsiMethod testMethod = getTestMethod(element, false);
PsiPackage testPackage;
if (element instanceof PsiPackage) {
testPackage = (PsiPackage) element;
} else {
if (element instanceof PsiDirectory) {
testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element));
} else {
testPackage = null;
}
}
PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null;
RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()).getConfigurationTemplate(configurationFactory);
Module predefinedModule = ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule();
String vmParameters = predefinedConfiguration instanceof JUnitConfiguration ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters() : null;
if (vmParameters != null && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) {
return false;
}
if (paramSetName != null && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters())) {
return false;
}
TestObject testobject = unitConfiguration.getTestObject();
if (testobject != null) {
if (testobject.isConfiguredByElement(unitConfiguration, testClass, testMethod, testPackage, testDir)) {
Module configurationModule = unitConfiguration.getConfigurationModule().getModule();
if (Comparing.equal(location.getModule(), configurationModule)) {
return true;
}
if (Comparing.equal(predefinedModule, configurationModule)) {
return true;
}
}
}
return false;
}
Aggregations