Skip to content

Commit

Permalink
refs #3926 - extended repeatable annotations support
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Apr 18, 2021
1 parent 56d233b commit 3180c72
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -317,23 +318,28 @@ public static <A extends Annotation> A getAnnotation(Class<?> cls, Class<A> anno
* @return List of repeatable annotations if it is found
*/
public static <A extends Annotation> List<A> getRepeatableAnnotations(Method method, Class<A> annotationClass) {
Set<A> annotationsSet = new LinkedHashSet<>();
A[] annotations = method.getAnnotationsByType(annotationClass);
if (annotations == null || annotations.length == 0) {
for (Annotation metaAnnotation : method.getAnnotations()) {
annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass);
if (annotations != null && annotations.length > 0) {
return Arrays.asList(annotations);
}
if (annotations != null) {
annotationsSet.addAll(Arrays.asList(annotations));
}
for (Annotation metaAnnotation : method.getAnnotations()) {
annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass);
if (annotations != null && annotations.length > 0) {
annotationsSet.addAll(Arrays.asList(annotations));
}
Method superclassMethod = getOverriddenMethod(method);
if (superclassMethod != null) {
return getRepeatableAnnotations(superclassMethod, annotationClass);
}
Method superclassMethod = getOverriddenMethod(method);
if (superclassMethod != null) {
List<A> superAnnotations = getRepeatableAnnotations(superclassMethod, annotationClass);
if (superAnnotations != null) {
annotationsSet.addAll(superAnnotations);
}
}
if (annotations == null) {
if (annotationsSet.isEmpty()) {
return null;
}
return Arrays.asList(annotations);
return new ArrayList<>(annotationsSet);
}

public static <A extends Annotation> List<A> getRepeatableAnnotations(Class<?> cls, Class<A> annotationClass) {
Expand Down

0 comments on commit 3180c72

Please sign in to comment.