|
18 | 18 | import java.util.Collections; |
19 | 19 | import java.util.Comparator; |
20 | 20 | import java.util.HashSet; |
| 21 | +import java.util.LinkedHashSet; |
21 | 22 | import java.util.List; |
22 | 23 | import java.util.Optional; |
23 | 24 | import java.util.Set; |
@@ -317,23 +318,28 @@ public static <A extends Annotation> A getAnnotation(Class<?> cls, Class<A> anno |
317 | 318 | * @return List of repeatable annotations if it is found |
318 | 319 | */ |
319 | 320 | public static <A extends Annotation> List<A> getRepeatableAnnotations(Method method, Class<A> annotationClass) { |
| 321 | + Set<A> annotationsSet = new LinkedHashSet<>(); |
320 | 322 | A[] annotations = method.getAnnotationsByType(annotationClass); |
321 | | - if (annotations == null || annotations.length == 0) { |
322 | | - for (Annotation metaAnnotation : method.getAnnotations()) { |
323 | | - annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass); |
324 | | - if (annotations != null && annotations.length > 0) { |
325 | | - return Arrays.asList(annotations); |
326 | | - } |
| 323 | + if (annotations != null) { |
| 324 | + annotationsSet.addAll(Arrays.asList(annotations)); |
| 325 | + } |
| 326 | + for (Annotation metaAnnotation : method.getAnnotations()) { |
| 327 | + annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass); |
| 328 | + if (annotations != null && annotations.length > 0) { |
| 329 | + annotationsSet.addAll(Arrays.asList(annotations)); |
327 | 330 | } |
328 | | - Method superclassMethod = getOverriddenMethod(method); |
329 | | - if (superclassMethod != null) { |
330 | | - return getRepeatableAnnotations(superclassMethod, annotationClass); |
| 331 | + } |
| 332 | + Method superclassMethod = getOverriddenMethod(method); |
| 333 | + if (superclassMethod != null) { |
| 334 | + List<A> superAnnotations = getRepeatableAnnotations(superclassMethod, annotationClass); |
| 335 | + if (superAnnotations != null) { |
| 336 | + annotationsSet.addAll(superAnnotations); |
331 | 337 | } |
332 | 338 | } |
333 | | - if (annotations == null) { |
| 339 | + if (annotationsSet.isEmpty()) { |
334 | 340 | return null; |
335 | 341 | } |
336 | | - return Arrays.asList(annotations); |
| 342 | + return new ArrayList<>(annotationsSet); |
337 | 343 | } |
338 | 344 |
|
339 | 345 | public static <A extends Annotation> List<A> getRepeatableAnnotations(Class<?> cls, Class<A> annotationClass) { |
|
0 commit comments