mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
java sm locator: accept vm class names (IDEA-105556)
This commit is contained in:
@@ -22,10 +22,11 @@ import com.intellij.execution.junit2.info.MethodLocation;
|
||||
import com.intellij.execution.testframework.sm.runner.SMTestLocator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.ClassUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -50,32 +51,27 @@ public class JavaTestLocator implements SMTestLocator {
|
||||
path = path.substring(0, idx);
|
||||
}
|
||||
|
||||
JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
|
||||
if (SUITE_PROTOCOL.equals(protocol)) {
|
||||
path = StringUtil.trimEnd(path, ".");
|
||||
PsiClass[] classes = javaPsiFacade.findClasses(path, scope);
|
||||
if (classes.length > 0) {
|
||||
PsiClass aClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), path, null, true, scope);
|
||||
if (aClass != null) {
|
||||
results = ContainerUtil.newSmartList();
|
||||
for (PsiClass aClass : classes) {
|
||||
results.add(paramName != null ? PsiMemberParameterizedLocation.getParameterizedLocation(aClass, paramName)
|
||||
: new PsiLocation<PsiClass>(project, aClass));
|
||||
}
|
||||
results.add(paramName != null ? PsiMemberParameterizedLocation.getParameterizedLocation(aClass, paramName)
|
||||
: new PsiLocation<PsiClass>(project, aClass));
|
||||
}
|
||||
}
|
||||
else if (TEST_PROTOCOL.equals(protocol)) {
|
||||
String className = StringUtil.getPackageName(path);
|
||||
if (!StringUtil.isEmpty(className)) {
|
||||
String methodName = StringUtil.getShortName(path);
|
||||
PsiClass[] classes = javaPsiFacade.findClasses(className, scope);
|
||||
if (classes.length > 0) {
|
||||
PsiClass aClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), className, null, true, scope);
|
||||
if (aClass != null) {
|
||||
results = ContainerUtil.newSmartList();
|
||||
for (PsiClass aClass : classes) {
|
||||
PsiMethod[] methods = aClass.findMethodsByName(methodName, true);
|
||||
if (methods.length > 0) {
|
||||
for (PsiMethod method : methods) {
|
||||
results.add(paramName != null ? new PsiMemberParameterizedLocation(project, method, aClass, paramName)
|
||||
: MethodLocation.elementInClass(method, aClass));
|
||||
}
|
||||
PsiMethod[] methods = aClass.findMethodsByName(methodName, true);
|
||||
if (methods.length > 0) {
|
||||
for (PsiMethod method : methods) {
|
||||
results.add(paramName != null ? new PsiMemberParameterizedLocation(project, method, aClass, paramName)
|
||||
: MethodLocation.elementInClass(method, aClass));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,4 +130,23 @@ public class JUnitRerunFailedTestsTest extends LightCodeInsightFixtureTestCase
|
||||
});
|
||||
assertNull(TestMethods.getTestPresentation(testProxy, project, searchScope));
|
||||
}
|
||||
|
||||
public void testInnerClass() throws Exception {
|
||||
myFixture.addClass("public class TestClass {\n" +
|
||||
" public static class Tests extends junit.framework.TestCase {\n" +
|
||||
" public void testFoo() throws Exception {}\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
|
||||
final SMTestProxy testProxy = new SMTestProxy("testFoo", false, "java:test://TestClass$Tests.testFoo");
|
||||
final Project project = getProject();
|
||||
final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
|
||||
testProxy.setLocator(JavaTestLocator.INSTANCE);
|
||||
Location location = testProxy.getLocation(project, searchScope);
|
||||
assertNotNull(location);
|
||||
PsiElement element = location.getPsiElement();
|
||||
assertTrue(element instanceof PsiMethod);
|
||||
String name = ((PsiMethod)element).getName();
|
||||
assertEquals(name, "testFoo");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user