Java Utililty Methods Reflection Annotation Find

List of utility methods to do Reflection Annotation Find

Description

The list of methods to do Reflection Annotation Find are organized into topic(s).

Method

TfindAnnotation(AnnotatedElement annotated, Class annotationClass)
find Annotation
T ret;
if (annotated == null) {
    ret = null;
} else {
    ret = annotated.getAnnotation(annotationClass);
return ret;
AfindAnnotation(AnnotatedElement annotatedElement, Class annotationClass)
Deep search of specified annotation considering "annotation inheritance" (annotation annotated with specified annotation).
Objects.requireNonNull(annotatedElement);
Objects.requireNonNull(annotationClass);
A result = annotatedElement.getAnnotation(annotationClass);
if (result != null) {
    return result;
return findAnnotationInAnnotations(annotatedElement, annotationClass);
AfindAnnotation(AnnotatedElement annotatedElement, Class annotationType)
Searches for an annotation of a given type that's been applied to an element either directly (as a regular annotation) or indirectly (as a meta-annotations, i.e.
if (annotationType == null) {
    return null;
return findAnnotation(annotatedElement, annotationType, new HashSet<Annotation>());
TfindAnnotation(AnnotatedElement element, Class annotationType)
Find an annotation of given annotationType on the given element , considering that the given annotationType may be present as a meta annotation on any other annotation on that element.
return (T) findAnnotation(element, annotationType.getName());
TfindAnnotation(Annotation parentAnnotation, Class annotationType)
Finds annotation of type specified in parameter, inside of other annotation.
for (Annotation childAnnotation : parentAnnotation.annotationType().getAnnotations()) {
    if (childAnnotation.annotationType().equals(annotationType)) {
        return (T) childAnnotation;
return null;
TfindAnnotation(Annotation[] parameterAnnotations, Class targetAnnotation)
Utility method to find if an annotation type is present in an array of annotations.
for (int i = 0; i < parameterAnnotations.length; i++) {
    Annotation annotation = parameterAnnotations[i];
    if (targetAnnotation.isInstance(annotation))
        return targetAnnotation.cast(annotation);
return null;
TfindAnnotation(Annotation[] searchList, Class annotation)
find Annotation
if (searchList == null) {
    return null;
for (Annotation ann : searchList) {
    if (ann.annotationType().equals(annotation)) {
        return (T) ann;
return null;
AfindAnnotation(Class clazz, Class annotationType)
find Annotation
A annotation = getAnnotation(clazz, annotationType);
Class<?> cl = clazz;
if (annotation == null) {
    annotation = searchOnInterfaces(clazz, annotationType, cl.getInterfaces());
while (annotation == null) {
    cl = cl.getSuperclass();
    if (cl == null || cl == Object.class) {
...
TfindAnnotation(Class clazz, Class annotationType)
find Annotation
T annotation = (T) clazz.getAnnotation(annotationType);
if (annotation != null)
    return annotation;
Class clazzes[] = clazz.getInterfaces();
int len = clazzes.length;
for (int i = 0; i < len; i++) {
    Class ifc = clazzes[i];
    annotation = findAnnotation(ifc, annotationType);
...
AnnotationfindAnnotation(Class aClass, Class annotationClass)
Finds an annotation of the class aClass by looking for an annotation matching the class annotationClass
for (Annotation annotation : aClass.getAnnotations()) {
    if (annotation.annotationType().equals(annotationClass)) {
        return annotation;
return null;