mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit 5: test factory method navigation with dynamic tests navigation to parent methods (IDEA-162200)
This commit is contained in:
@@ -58,34 +58,46 @@ public class JavaTestLocator implements SMTestLocator {
|
||||
results = ContainerUtil.newSmartList();
|
||||
results.add(createClassNavigatable(paramName, aClass));
|
||||
}
|
||||
else {
|
||||
results = collectMethodNavigatables(path, project, scope, paramName);
|
||||
}
|
||||
}
|
||||
else if (TEST_PROTOCOL.equals(protocol)) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
results = collectMethodNavigatables(path, project, scope, paramName);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private Location createClassNavigatable(String paramName, @NotNull PsiClass aClass) {
|
||||
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;
|
||||
}
|
||||
|
||||
private static Location createClassNavigatable(String paramName, @NotNull PsiClass aClass) {
|
||||
return paramName != null ? PsiMemberParameterizedLocation.getParameterizedLocation(aClass, paramName)
|
||||
: new PsiLocation<>(aClass.getProject(), aClass);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user