|
38 | 38 | import java.util.function.Predicate; |
39 | 39 |
|
40 | 40 | import static io.microsphere.collection.CollectionUtils.isEmpty; |
41 | | -import static io.microsphere.collection.CollectionUtils.isNotEmpty; |
42 | 41 | import static io.microsphere.collection.ListUtils.first; |
| 42 | +import static io.microsphere.collection.ListUtils.newLinkedList; |
43 | 43 | import static io.microsphere.collection.Lists.ofList; |
44 | 44 | import static io.microsphere.collection.MapUtils.immutableEntry; |
45 | 45 | import static io.microsphere.collection.MapUtils.toFixedMap; |
@@ -1761,9 +1761,9 @@ public static boolean isNativeAnnotationType(Class<? extends Annotation> annotat |
1761 | 1761 | * <p>If either the annotated element or the meta-annotation type is {@code null}, |
1762 | 1762 | * this method will return {@code null}.</p> |
1763 | 1763 | * |
1764 | | - * @param annotatedElement the element to search for meta-annotations on |
| 1764 | + * @param annotatedElement the element to search for meta-annotations on |
1765 | 1765 | * @param metaAnnotationType the type of meta-annotation to look for |
1766 | | - * @param <A> the type of the meta-annotation to find |
| 1766 | + * @param <A> the type of the meta-annotation to find |
1767 | 1767 | * @return the first matching meta-annotation of the specified type, or {@code null} if none is found |
1768 | 1768 | */ |
1769 | 1769 | @Nullable |
@@ -1822,23 +1822,32 @@ public static <A extends Annotation> A findMetaAnnotation(AnnotatedElement annot |
1822 | 1822 | * <p>If either the annotated element or the meta-annotation type is {@code null}, |
1823 | 1823 | * this method will return an empty list.</p> |
1824 | 1824 | * |
1825 | | - * @param annotatedElement the element to search for meta-annotations on |
| 1825 | + * @param annotatedElement the element to search for meta-annotations on |
1826 | 1826 | * @param metaAnnotationType the type of meta-annotation to look for |
1827 | | - * @param <A> the type of the meta-annotation to find |
| 1827 | + * @param <A> the type of the meta-annotation to find |
1828 | 1828 | * @return a read-only list of all matching meta-annotations of the specified type, never {@code null} |
1829 | 1829 | */ |
1830 | 1830 | @Nonnull |
1831 | 1831 | @Immutable |
1832 | 1832 | public static <A extends Annotation> List<A> findMetaAnnotations(AnnotatedElement annotatedElement, Class<A> metaAnnotationType) { |
1833 | | - return (List<A>) findDeclaredAnnotations(annotatedElement, annotation -> { |
| 1833 | + List<A> annotations = newLinkedList(); |
| 1834 | + findMetaAnnotations(annotatedElement, metaAnnotationType, annotations); |
| 1835 | + return unmodifiableList(annotations); |
| 1836 | + } |
| 1837 | + |
| 1838 | + static <A extends Annotation> void findMetaAnnotations(AnnotatedElement annotatedElement, Class<A> metaAnnotationType, List<A> annotations) { |
| 1839 | + findDeclaredAnnotations(annotatedElement, annotation -> { |
1834 | 1840 | Class<? extends Annotation> annotationType = annotation.annotationType(); |
1835 | 1841 | if (isNativeAnnotationType(annotationType)) { |
1836 | 1842 | return false; |
1837 | 1843 | } |
1838 | 1844 | if (annotationType.equals(metaAnnotationType)) { |
| 1845 | + annotations.add((A) annotation); |
1839 | 1846 | return true; |
1840 | 1847 | } |
1841 | | - return isNotEmpty(findMetaAnnotations(annotationType, metaAnnotationType)); |
| 1848 | + // Recursively find meta-annotations on the annotation type |
| 1849 | + findMetaAnnotations(annotationType, metaAnnotationType, annotations); |
| 1850 | + return false; |
1842 | 1851 | }); |
1843 | 1852 | } |
1844 | 1853 |
|
|
0 commit comments