Skip to content

Commit 2380414

Browse files
committed
support for meta-annotations
1 parent f49f9ca commit 2380414

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

src/main/java/org/axonframework/intellij/ide/plugin/handler/DefaultEventHandlerProvider.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,56 @@
88
import com.intellij.psi.PsiMethod;
99
import com.intellij.psi.PsiReference;
1010
import com.intellij.psi.search.GlobalSearchScope;
11+
import com.intellij.psi.search.searches.AnnotatedElementsSearch;
1112
import com.intellij.psi.search.searches.ReferencesSearch;
1213
import com.intellij.psi.util.PsiTreeUtil;
1314
import com.intellij.util.Processor;
1415
import com.intellij.util.Query;
1516

1617
class DefaultEventHandlerProvider implements HandlerProvider {
1718
@Override
18-
public void scanHandlers(Project project, GlobalSearchScope scope, final Registrar registrar) {
19+
public void scanHandlers(Project project, final GlobalSearchScope scope, final Registrar registrar) {
1920
for (final AnnotationTypes annotationType : AnnotationTypes.values()) {
20-
PsiClass eventHandlerAnnotation = JavaPsiFacade.getInstance(project)
21+
final PsiClass eventHandlerAnnotation = JavaPsiFacade.getInstance(project)
2122
.findClass(annotationType.getFullyQualifiedName(),
2223
GlobalSearchScope.allScope(project));
24+
2325
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>() {
2628
@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);
4031
return true;
4132
}
4233
});
4334
}
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+
});
4461
}
4562
}
4663

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.axonframework.intellij.ide.plugin.handler;
2+
3+
import com.intellij.openapi.util.Condition;
4+
import com.intellij.psi.PsiAnnotation;
5+
import com.intellij.psi.PsiElement;
6+
7+
public class IsAnnotationCondition implements Condition<PsiElement> {
8+
9+
@Override
10+
public boolean value(PsiElement psiElement) {
11+
return psiElement instanceof PsiAnnotation;
12+
}
13+
}

0 commit comments

Comments
 (0)