|
8 | 8 | import com.intellij.psi.PsiMethod;
|
9 | 9 | import com.intellij.psi.PsiReference;
|
10 | 10 | import com.intellij.psi.search.GlobalSearchScope;
|
| 11 | +import com.intellij.psi.search.searches.AnnotatedElementsSearch; |
11 | 12 | import com.intellij.psi.search.searches.ReferencesSearch;
|
12 | 13 | import com.intellij.psi.util.PsiTreeUtil;
|
13 | 14 | import com.intellij.util.Processor;
|
14 | 15 | import com.intellij.util.Query;
|
15 | 16 |
|
16 | 17 | class DefaultEventHandlerProvider implements HandlerProvider {
|
17 | 18 | @Override
|
18 |
| - public void scanHandlers(Project project, GlobalSearchScope scope, final Registrar registrar) { |
| 19 | + public void scanHandlers(Project project, final GlobalSearchScope scope, final Registrar registrar) { |
19 | 20 | for (final AnnotationTypes annotationType : AnnotationTypes.values()) {
|
20 |
| - PsiClass eventHandlerAnnotation = JavaPsiFacade.getInstance(project) |
| 21 | + final PsiClass eventHandlerAnnotation = JavaPsiFacade.getInstance(project) |
21 | 22 | .findClass(annotationType.getFullyQualifiedName(),
|
22 | 23 | GlobalSearchScope.allScope(project));
|
| 24 | + |
23 | 25 | if (eventHandlerAnnotation != null) {
|
24 |
| - Query<PsiReference> annotationUsages = ReferencesSearch.search(eventHandlerAnnotation, scope); |
25 |
| - annotationUsages.forEachAsync(new Processor<PsiReference>() { |
| 26 | + final Query<PsiClass> customEventHandlers = AnnotatedElementsSearch.searchPsiClasses(eventHandlerAnnotation, scope); |
| 27 | + customEventHandlers.forEach(new Processor<PsiClass>() { |
26 | 28 | @Override
|
27 |
| - public boolean process(PsiReference psiReference) { |
28 |
| - PsiMethod method = (PsiMethod) PsiTreeUtil.findFirstParent(psiReference.getElement(), |
29 |
| - new IsMethodCondition()); |
30 |
| - if (method != null) { |
31 |
| - // this doesn't say the method is annotated |
32 |
| - final PsiAnnotation annotation = locateAnnotation(method); |
33 |
| - if (annotation != null) { |
34 |
| - Handler handler = createHandlerBasedOnAnnotation(method, annotation); |
35 |
| - if (handler != null) { |
36 |
| - registrar.registerHandler(handler); |
37 |
| - } |
38 |
| - } |
39 |
| - } |
| 29 | + public boolean process(final PsiClass psiClass) { |
| 30 | + registerEventHandlerAnnotation(scope, registrar, eventHandlerAnnotation); |
40 | 31 | return true;
|
41 | 32 | }
|
42 | 33 | });
|
43 | 34 | }
|
| 35 | + |
| 36 | + registerEventHandlerAnnotation(scope, registrar, eventHandlerAnnotation); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + private void registerEventHandlerAnnotation(final GlobalSearchScope scope, final Registrar registrar, final PsiClass eventHandlerAnnotation) { |
| 41 | + if (eventHandlerAnnotation != null) { |
| 42 | + Query<PsiReference> annotationUsages = ReferencesSearch.search(eventHandlerAnnotation, scope); |
| 43 | + annotationUsages.forEachAsync(new Processor<PsiReference>() { |
| 44 | + @Override |
| 45 | + public boolean process(PsiReference psiReference) { |
| 46 | + PsiMethod method = (PsiMethod) PsiTreeUtil.findFirstParent(psiReference.getElement(), |
| 47 | + new IsMethodCondition()); |
| 48 | + if (method != null) { |
| 49 | + // this doesn't say the method is annotated |
| 50 | + final PsiAnnotation annotation = locateAnnotation(method); |
| 51 | + if (annotation != null) { |
| 52 | + Handler handler = createHandlerBasedOnAnnotation(method, annotation); |
| 53 | + if (handler != null) { |
| 54 | + registrar.registerHandler(handler); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + return true; |
| 59 | + } |
| 60 | + }); |
44 | 61 | }
|
45 | 62 | }
|
46 | 63 |
|
|
0 commit comments