|
52 | 52 | import org.eclipse.jdt.core.search.SearchPattern; |
53 | 53 | import org.eclipse.jdt.core.search.SearchRequestor; |
54 | 54 |
|
| 55 | +import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner; |
| 56 | +import org.eclipse.jdt.internal.core.JavaProject; |
| 57 | +import org.eclipse.jdt.internal.core.NameLookup; |
55 | 58 | import org.eclipse.jdt.internal.core.PackageFragmentRoot; |
56 | 59 | import org.eclipse.jdt.internal.junit.JUnitCorePlugin; |
57 | 60 | import org.eclipse.jdt.internal.junit.buildpath.BuildPathSupport; |
@@ -169,10 +172,10 @@ private static boolean hasJUnitJupiterTestAnnotation(IJavaProject project, int j |
169 | 172 | try { |
170 | 173 | if (project != null) { |
171 | 174 | String junitBundlePrefix = JUNIT_PLATFORM_COMMONS_PREFIX; |
172 | | - IType type= project.findType(JUnitCorePlugin.JUNIT5_TESTABLE_ANNOTATION_NAME); |
| 175 | + IType type= findAnnotation(project, JUnitCorePlugin.JUNIT5_TESTABLE_ANNOTATION_NAME); |
173 | 176 | if (type == null) { |
174 | 177 | junitBundlePrefix = JUNIT_PLATFORM_SUITE_API_PREFIX; |
175 | | - type= project.findType(JUnitCorePlugin.JUNIT5_SUITE_ANNOTATION_NAME); |
| 178 | + type= findAnnotation(project, JUnitCorePlugin.JUNIT5_SUITE_ANNOTATION_NAME); |
176 | 179 | } |
177 | 180 | if (type != null) { |
178 | 181 | // check if we have the right JUnit JUpiter version |
@@ -331,4 +334,22 @@ public static void findSuiteMethods(IJavaElement element, Set<IType> result, IPr |
331 | 334 | SearchParticipant[] participants= new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; |
332 | 335 | new SearchEngine().search(suitePattern, participants, scope, requestor, pm); |
333 | 336 | } |
| 337 | + |
| 338 | + private static IType findAnnotation(IJavaProject project, String fullyQualifiedName) throws JavaModelException { |
| 339 | + if (project instanceof JavaProject p) { |
| 340 | + NameLookup lookup= p.newNameLookup(DefaultWorkingCopyOwner.PRIMARY); |
| 341 | + NameLookup.Answer answer = lookup.findType( |
| 342 | + fullyQualifiedName, |
| 343 | + false /* no partial matches */, |
| 344 | + NameLookup.ACCEPT_ANNOTATIONS, |
| 345 | + false /* no secondary types */, |
| 346 | + true /* wait for indexer */, |
| 347 | + true /* check restrictions */, |
| 348 | + null); |
| 349 | + if (answer != null) { |
| 350 | + return answer.type; |
| 351 | + } |
| 352 | + } |
| 353 | + return null; |
| 354 | + } |
334 | 355 | } |
0 commit comments