From afeda511e1df3e471cfc8f451a36937177123c9c Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Thu, 16 Feb 2017 19:44:51 +0100 Subject: [PATCH] avoid alternative resolve searching for package EA-95336 - INRE: FileBasedIndexImpl.handleDumbMode --- .../com/intellij/execution/junit/JUnitUtil.java | 12 +++++++++++- .../com/intellij/execution/junit/TestPackage.java | 14 +++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java index b25d6c7d09ca..3fe593f45038 100644 --- a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java +++ b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java @@ -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()); diff --git a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java index 1a45144ef7e8..46c7e1f76c65 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java @@ -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);