IDEA-141685 Goto testdata broken: hanging fixed

This commit is contained in:
Dmitry Avdeev
2015-06-19 20:08:02 +03:00
parent c3e0947e1c
commit c04a98fd0d
2 changed files with 32 additions and 26 deletions
@@ -19,6 +19,9 @@ import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.PsiModificationTracker;
import com.intellij.testIntegration.TestFramework;
import org.jetbrains.annotations.Nullable;
@@ -51,7 +54,18 @@ public abstract class TestFrameworks {
}
@Nullable
public static TestFramework detectFramework(PsiClass psiClass) {
public static TestFramework detectFramework(final PsiClass psiClass) {
return CachedValuesManager.getCachedValue(psiClass, new CachedValueProvider<TestFramework>() {
@Nullable
@Override
public Result<TestFramework> compute() {
return Result.create(computeFramework(psiClass), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
}
});
}
@Nullable
private static TestFramework computeFramework(PsiClass psiClass) {
for (TestFramework framework : Extensions.getExtensions(TestFramework.EXTENSION_NAME)) {
if (framework.isTestClass(psiClass)) {
return framework;
@@ -63,7 +77,6 @@ public abstract class TestFrameworks {
return framework;
}
}
return null;
}
}
@@ -16,8 +16,8 @@
package org.jetbrains.idea.devkit.testAssistant;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.TestFrameworks;
import com.intellij.ide.util.gotoByName.GotoFileModel;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
@@ -66,20 +66,11 @@ public class TestDataGuessByExistingFilesUtil {
*/
@Nullable
static List<String> collectTestDataByExistingFiles(@NotNull PsiMethod psiMethod) {
String testName = getTestName(psiMethod);
if (testName == null) {
return null;
}
PsiFile psiFile = PsiTreeUtil.getParentOfType(psiMethod, PsiFile.class);
if (psiFile == null) {
return null;
}
TestDataDescriptor descriptor = buildDescriptorFromExistingTestData(psiMethod);
if (descriptor == null || !descriptor.isComplete()) {
return null;
}
return descriptor.generate(testName);
return descriptor.generate();
}
static String guessTestDataName(PsiMethod method) {
@@ -87,14 +78,16 @@ public class TestDataGuessByExistingFilesUtil {
if (testName == null) return null;
PsiClass psiClass = method.getContainingClass();
if (psiClass == null) return null;
int count = 5;
PsiMethod prev = PsiTreeUtil.getPrevSiblingOfType(method, PsiMethod.class);
while (prev != null) {
while (prev != null && count-- > 0) {
String s = getFilePath(prev, testName);
if (s != null) return s;
prev = PsiTreeUtil.getPrevSiblingOfType(method, PsiMethod.class);
}
count = 5;
PsiMethod next = PsiTreeUtil.getNextSiblingOfType(method, PsiMethod.class);
while (next != null) {
while (next != null && count-- > 0) {
String s = getFilePath(next, testName);
if (s != null) return s;
next = PsiTreeUtil.getPrevSiblingOfType(method, PsiMethod.class);
@@ -119,14 +112,7 @@ public class TestDataGuessByExistingFilesUtil {
return null;
}
TestFramework[] frameworks = Extensions.getExtensions(TestFramework.EXTENSION_NAME);
TestFramework framework = null;
for (TestFramework each : frameworks) {
if (each.isTestClass(psiClass)) {
framework = each;
break;
}
}
TestFramework framework = TestFrameworks.detectFramework(psiClass);
if (framework == null || isUtilityMethod(method, psiClass, framework)) {
return null;
@@ -234,7 +220,7 @@ public class TestDataGuessByExistingFilesUtil {
break;
}
}
return new TestDataDescriptor(descriptors);
return new TestDataDescriptor(descriptors, test);
}
private static Collection<String> getAllFileNames(final String testName, final GotoFileModel model) {
@@ -374,11 +360,13 @@ public class TestDataGuessByExistingFilesUtil {
}
private static class TestDataDescriptor {
private static final TestDataDescriptor NOTHING_FOUND = new TestDataDescriptor(Collections.<TestLocationDescriptor>emptyList());
private static final TestDataDescriptor NOTHING_FOUND = new TestDataDescriptor(Collections.<TestLocationDescriptor>emptyList(), null);
private final List<TestLocationDescriptor> myDescriptors = new ArrayList<TestLocationDescriptor>();
private final String myTestName;
TestDataDescriptor(Collection<TestLocationDescriptor> descriptors) {
TestDataDescriptor(Collection<TestLocationDescriptor> descriptors, String testName) {
myTestName = testName;
myDescriptors.addAll(descriptors);
}
@@ -400,6 +388,11 @@ public class TestDataGuessByExistingFilesUtil {
return generate(testName, null);
}
@NotNull
public List<String> generate() {
return generate(myTestName, null);
}
@NotNull
public List<String> generate(@NotNull final String testName, String root) {
List<String> result = new ArrayList<String>();