|
18 | 18 |
|
19 | 19 | import java.lang.annotation.Annotation;
|
20 | 20 | import java.lang.reflect.Method;
|
| 21 | +import java.util.HashSet; |
21 | 22 | import java.util.LinkedHashSet;
|
22 | 23 | import java.util.Set;
|
23 | 24 | import java.util.function.Consumer;
|
@@ -55,24 +56,31 @@ public abstract class RuntimeHintsUtils {
|
55 | 56 | * @see SynthesizedAnnotation
|
56 | 57 | */
|
57 | 58 | public static void registerAnnotation(RuntimeHints hints, Class<?> annotationType) {
|
| 59 | + hints.reflection().registerType(annotationType, ANNOTATION_HINT); |
58 | 60 | Set<Class<?>> allAnnotations = new LinkedHashSet<>();
|
59 |
| - allAnnotations.add(annotationType); |
60 |
| - collectAliasedAnnotations(allAnnotations, annotationType); |
| 61 | + collectAliasedAnnotations(new HashSet<>(), allAnnotations, annotationType); |
61 | 62 | allAnnotations.forEach(annotation -> hints.reflection().registerType(annotation, ANNOTATION_HINT));
|
62 |
| - if (allAnnotations.size() > 1) { |
| 63 | + if (allAnnotations.size() > 0) { |
63 | 64 | hints.proxies().registerJdkProxy(annotationType, SynthesizedAnnotation.class);
|
64 | 65 | }
|
65 | 66 | }
|
66 | 67 |
|
67 |
| - private static void collectAliasedAnnotations(Set<Class<?>> types, Class<?> annotationType) { |
| 68 | + private static void collectAliasedAnnotations(Set<Class<?>> seen, Set<Class<?>> types, Class<?> annotationType) { |
| 69 | + if (seen.contains(annotationType)) { |
| 70 | + return; |
| 71 | + } |
| 72 | + seen.add(annotationType); |
68 | 73 | for (Method method : annotationType.getDeclaredMethods()) {
|
69 | 74 | MergedAnnotations methodAnnotations = MergedAnnotations.from(method);
|
70 | 75 | if (methodAnnotations.isPresent(AliasFor.class)) {
|
71 |
| - Class<?> aliasedAnnotation = methodAnnotations.get(AliasFor.class).getClass("annotation"); |
72 |
| - boolean process = (aliasedAnnotation != Annotation.class && !types.contains(aliasedAnnotation)); |
73 |
| - if (process) { |
74 |
| - types.add(aliasedAnnotation); |
75 |
| - collectAliasedAnnotations(types, aliasedAnnotation); |
| 76 | + Class<?> annotationAttribute = methodAnnotations.get(AliasFor.class).getClass("annotation"); |
| 77 | + Class<?> targetAnnotation = (annotationAttribute != Annotation.class |
| 78 | + ? annotationAttribute : annotationType); |
| 79 | + if (!types.contains(targetAnnotation)) { |
| 80 | + types.add(targetAnnotation); |
| 81 | + if (!targetAnnotation.equals(annotationType)) { |
| 82 | + collectAliasedAnnotations(seen, types, targetAnnotation); |
| 83 | + } |
76 | 84 | }
|
77 | 85 | }
|
78 | 86 | }
|
|
0 commit comments