public final class AnnotationUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T extends Annotation> |
findAnnotation(AnnotatedElement annotatedElement,
Class<T> annotationType)
|
static <T extends Annotation> |
findAnnotation(Class<?> clazz,
Class<T> annotationType)
Find a single
Annotation of annotationType on the
supplied Class, traversing its interfaces, annotations, and
superclasses if the annotation is not directly present on
the given class itself. |
static <T extends Annotation> |
findAnnotation(Method method,
Class<T> annotationType)
Find a single
Annotation of annotationType on the supplied
Method, traversing its super methods (i.e., from superclasses and
interfaces) if the annotation is not directly present on the given
method itself. |
static boolean |
isInJavaLangAnnotationPackage(Annotation annotation)
Determine if the supplied
Annotation is defined in the core JDK java.lang.annotation package. |
static boolean |
isInJavaLangAnnotationPackage(Class<? extends Annotation> annotationType)
Determine if the
Annotation with the supplied name is defined in the core JDK java.lang.annotation package. |
static boolean |
isInJavaLangAnnotationPackage(String annotationType)
Determine if the
Annotation with the supplied name is defined in the core JDK java.lang.annotation package. |
public static <T extends Annotation> Optional<T> findAnnotation(Class<?> clazz, Class<T> annotationType)
Annotation of annotationType on the
supplied Class, traversing its interfaces, annotations, and
superclasses if the annotation is not directly present on
the given class itself.
This method explicitly handles class-level annotations which are not
declared as inherited as well
as meta-annotations and annotations on interfaces.
The algorithm operates as follows:
Note: in this context, the term recursively means that the search process continues by returning to step #1 with the current interface, annotation, or superclass as the class to look for annotations on.
clazz - the class to look for annotations onannotationType - the annotation type to look for, both locally and as a meta-annotationpublic static <T extends Annotation> Optional<T> findAnnotation(AnnotatedElement annotatedElement, Class<T> annotationType)
Annotation of annotationType on the
supplied AnnotatedElement.
Meta-annotations will be searched if the annotation is not directly present on the supplied element.
Warning: this method operates generically on
annotated elements. In other words, this method does not execute
specialized search algorithms for classes or methods. If you require
the more specific semantics of findAnnotation(Class, Class)
or findAnnotation(Method, Class), invoke one of those methods
instead.
annotatedElement - the AnnotatedElement on which to find the annotationannotationType - the annotation type to look for, both locally and as a meta-annotationpublic static <T extends Annotation> Optional<T> findAnnotation(Method method, Class<T> annotationType)
Annotation of annotationType on the supplied
Method, traversing its super methods (i.e., from superclasses and
interfaces) if the annotation is not directly present on the given
method itself.
Correctly handles bridge Methods generated by the compiler.
Meta-annotations will be searched if the annotation is not directly present on the method.
Annotations on methods are not inherited by default, so we need to handle this explicitly.
method - the method to look for annotations onannotationType - the annotation type to look forpublic static boolean isInJavaLangAnnotationPackage(Annotation annotation)
Annotation is defined in the core JDK java.lang.annotation package.annotation - the annotation to checktrue if the annotation is in the java.lang.annotation packagepublic static boolean isInJavaLangAnnotationPackage(Class<? extends Annotation> annotationType)
Annotation with the supplied name is defined in the core JDK java.lang.annotation package.annotationType - the annotation type to checktrue if the annotation is in the java.lang.annotation packagepublic static boolean isInJavaLangAnnotationPackage(String annotationType)
Annotation with the supplied name is defined in the core JDK java.lang.annotation package.annotationType - the name of the annotation type to checktrue if the annotation is in the java.lang.annotation packageCopyright © 2019 Appulse. All rights reserved.