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

AnnotationfindAnnotation(Class classy, Class targetAnnotation)
find Annotation
Annotation[] annotations = classy.getAnnotations();
for (Annotation annotation : annotations) {
    if (targetAnnotation.isInstance(annotation)) {
        return annotation;
return null;
AnnotationfindAnnotation(Class clazz, Class annotationClass, Set> set)
find Annotation
if (clazz == null || set.contains(clazz) || clazz.equals(Object.class)) {
    return null;
set.add(clazz);
Annotation result = findAnnotation(clazz.getSuperclass(), annotationClass, set);
if (result != null) {
    return result;
Annotation findResult = Arrays.stream(clazz.getInterfaces())
        .map((Class<?> interf) -> findAnnotation(interf, annotationClass, set))
        .filter((Annotation annotation) -> annotation != null).findFirst().orElse(null);
if (findResult != null) {
    return findResult;
Annotation interfaceAnnotation = Arrays.stream(clazz.getDeclaredAnnotations())
        .filter((Annotation annotation) -> annotation.annotationType().equals(annotationClass)).findFirst()
        .orElse(null);
if (interfaceAnnotation != null) {
    return interfaceAnnotation;
return Arrays.stream(clazz.getDeclaredAnnotations())
        .map((Annotation annotation) -> findAnnotation(annotation.annotationType(), annotationClass, set))
        .filter((Annotation annotation) -> annotation != null).findFirst().orElse(null);
AfindAnnotation(Class clazz, Class annotationClass)
find Annotation
A annotation = clazz.getAnnotation(annotationClass);
if (null != annotation) {
    return annotation;
for (Class<?> ifc : clazz.getInterfaces()) {
    annotation = ifc.getAnnotation(annotationClass);
    if (null != annotation) {
        return annotation;
...
AfindAnnotation(Class clazz, Class annotationType)
Finds an annotation in a class type hierarchy.
if (clazz == null)
    throw new IllegalArgumentException("Clazz parameter can't be null");
A annotation = clazz.getAnnotation(annotationType);
if (annotation != null)
    return annotation;
for (Class<?> ifc : clazz.getInterfaces()) {
    annotation = findAnnotation(ifc, annotationType);
    if (annotation != null)
...
AfindAnnotation(Class clazz, Class annotationType)
Find a single Annotation of annotationType on the supplied Class , traversing its interfaces, annotations, and superclasses if the annotation is not present on the given class itself.
return findAnnotation(clazz, annotationType, new HashSet<Annotation>());
AfindAnnotation(Class clazz, Class annotationType)
find Annotation
A annotation = clazz.getAnnotation(annotationType);
if (annotation != null) {
    return annotation;
for (Class<?> ifc : clazz.getInterfaces()) {
    annotation = findAnnotation(ifc, annotationType);
    if (annotation != null) {
        return annotation;
...
AfindAnnotation(Class clazz, Class annotationType)
find Annotation
Preconditions.checkNotNull(clazz, "Class must not be null");
A annotation = clazz.getAnnotation(annotationType);
if (annotation != null) {
    return annotation;
for (Class<?> ifc : clazz.getInterfaces()) {
    annotation = findAnnotation(ifc, annotationType);
    if (annotation != null) {
...
TfindAnnotation(Class clazz, Class annotationClass)
find Annotation
T a = null;
Class<?> c = findClassWithAnnotation(clazz, annotationClass);
if (c != null) {
    a = c.getAnnotation(annotationClass);
return a;
TfindAnnotation(Class clazz, Class annotationClass)
find Annotation
while (clazz != null) {
    T t = clazz.getAnnotation(annotationClass);
    if (t != null) {
        return t;
    for (Class<?> interfaceClass : clazz.getInterfaces()) {
        t = interfaceClass.getAnnotation(annotationClass);
        if (t != null) {
...
TfindAnnotation(Class clazz, Class annotationClass)
Returns the annotation on the given class or the package of the class.
T ann = clazz.getAnnotation(annotationClass);
while (ann == null && clazz != null) {
    ann = clazz.getAnnotation(annotationClass);
    if (ann == null) {
        ann = clazz.getPackage().getAnnotation(annotationClass);
    if (ann == null) {
        clazz = clazz.getSuperclass();
...