avoid alternative resolve searching for package

EA-95336 - INRE: FileBasedIndexImpl.handleDumbMode
This commit is contained in:
Anna.Kozlova
2017-02-17 10:57:30 +01:00
parent 41117e053b
commit afeda511e1
2 changed files with 14 additions and 12 deletions
@@ -44,6 +44,7 @@ public class JUnitUtil {
@NonNls private static final String TEST_INTERFACE = "junit.framework.Test";
@NonNls private static final String TESTSUITE_CLASS = "junit.framework.TestSuite";
@NonNls public static final String TEST_ANNOTATION = "org.junit.Test";
@NonNls public static final String TEST5_PACKAGE_FQN = "org.junit.jupiter.api";
@NonNls public static final String TEST5_ANNOTATION = "org.junit.jupiter.api.Test";
@NonNls public static final String CUSTOM_TESTABLE_ANNOTATION = "org.junit.platform.commons.annotation.Testable";
@NonNls public static final String TEST5_FACTORY_ANNOTATION = "org.junit.jupiter.api.TestFactory";
@@ -251,7 +252,8 @@ public class JUnitUtil {
}
public static boolean isJUnit5(GlobalSearchScope scope, Project project) {
return JavaPsiFacade.getInstance(project).findClass(TEST5_ANNOTATION, scope) != null;
PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(TEST5_PACKAGE_FQN);
return aPackage != null && aPackage.getDirectories(scope).length > 0;
}
public static boolean isTestAnnotated(final PsiMethod method) {
@@ -285,6 +287,14 @@ public class JUnitUtil {
return getTestCaseClass(scope.getLibrariesScope(), scope.getProject());
}
public static void checkTestCase(SourceScope scope, Project project) throws NoJUnitException {
if (scope == null) throw new NoJUnitException();
PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage("org.junit");
if (aPackage == null || aPackage.getDirectories(scope.getLibrariesScope()).length == 0) {
throw new NoJUnitException();
}
}
private static PsiClass getTestCaseClass(final GlobalSearchScope scope, final Project project) throws NoJUnitException {
PsiClass testCaseClass = getTestCaseClassOrNull(scope, project);
if (testCaseClass == null) throw new NoJUnitException(scope.getDisplayName());
@@ -26,7 +26,6 @@ import com.intellij.execution.testframework.SourceScope;
import com.intellij.execution.testframework.TestSearchScope;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Ref;
@@ -99,16 +98,9 @@ public class TestPackage extends TestObject {
final JavaParameters javaParameters = super.createJavaParameters();
final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
final Project project = getConfiguration().getProject();
final DumbService dumbService = DumbService.getInstance(project);
try {
dumbService.setAlternativeResolveEnabled(true);
final SourceScope sourceScope = data.getScope().getSourceScope(getConfiguration());
if (sourceScope == null || !isJUnit5(getConfiguration().getConfigurationModule().getModule(), sourceScope, project)) { //check for junit 5
getClassFilter(data);//check if junit 4 found
}
}
finally {
dumbService.setAlternativeResolveEnabled(false);
final SourceScope sourceScope = data.getScope().getSourceScope(getConfiguration());
if (sourceScope == null || !isJUnit5(getConfiguration().getConfigurationModule().getModule(), sourceScope, project)) { //check for junit 5
JUnitUtil.checkTestCase(sourceScope, project);
}
createTempFiles(javaParameters);