junit 5: test factory method navigation with dynamic tests navigation to parent methods (IDEA-162200)

This commit is contained in:
Anna.Kozlova
2016-10-07 19:40:26 +02:00
parent 5a81762576
commit 127ac1f9e4
3 changed files with 44 additions and 26 deletions
@@ -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);
}