Class AnnotationUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A extends Annotation>
Optional<A> findAnnotation(Class<?> type, Class<A> annotationType) Finds an annotation that is directly present or meta-present on the given class or on an interface it implements.static <A extends Annotation>
List<A> findRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType) Find all repeatable annotations ofannotationTypethat are either present, indirectly present, or meta-present on the suppliedAnnotatedElement.static booleanisAnnotated(Class<?> type, String annotationName) Checks whether an annotation is directly present or meta-present on the given class, for an annotation type that may not be on the classpath.
-
Method Details
-
findAnnotation
public static <A extends Annotation> Optional<A> findAnnotation(Class<?> type, Class<A> annotationType) Finds an annotation that is directly present or meta-present on the given class or on an interface it implements. If the annotation type is@Inherited, superclasses are searched as well, including through a composed annotation that is not itself inherited.- Type Parameters:
A- the annotation type- Parameters:
type- the class to search onannotationType- the annotation type to search for- Returns:
- the annotation, if there is one
- Since:
- 5.2.1
-
isAnnotated
Checks whether an annotation is directly present or meta-present on the given class, for an annotation type that may not be on the classpath.- Parameters:
type- the class to search onannotationName- the fully qualified name of the annotation type- Returns:
- true if the annotation is present
- Since:
- 5.2.1
-
findRepeatableAnnotations
public static <A extends Annotation> List<A> findRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType) Find all repeatable annotations ofannotationTypethat are either present, indirectly present, or meta-present on the suppliedAnnotatedElement.This method extends the functionality of
AnnotatedElement.getAnnotationsByType(Class)with additional support for meta-annotations.In addition, if the element is a class and the repeatable annotation is
@Inherited, this method will search on superclasses first in order to support top-down semantics. The result is that this algorithm finds repeatable annotations that would be shadowed and therefore not visible according to Java's standard semantics for inherited, repeatable annotations.If the element is a class and the repeatable annotation is not discovered within the class hierarchy, this method will additionally search on interfaces implemented by each class in the hierarchy.
If the supplied
elementisnull, this method simply returns an empty list.- Type Parameters:
A- the annotation instance- Parameters:
element- the element to search on, potentiallynullannotationType- the repeatable annotation type to search for; nevernull- Returns:
- the list of all such annotations found; neither
nullnor mutable - See Also:
-