public static < A extends Annotation > List < AnnotatedClass < A > > allTypeAnnotations ( final Class < ? > clazz , final Class < A > annotation , final boolean recurse ) { final List < AnnotatedClass < A > > ret = new ArrayList <> ( ) ; final A curClassAnnotation = clazz . getAnnotation ( annotation ) ; if ( curClassAnnotation != null ) ret . add ( new AnnotatedClass < A > ( clazz , curClassAnnotation ) ) ; if ( ! recurse ) return ret ; final Class < ? > superClazz = clazz . getSuperclass ( ) ; if ( superClazz != null ) ret . addAll ( allTypeAnnotations ( superClazz , annotation , recurse ) ) ; // Now do the interfaces. final Class < ? > [ ] ifaces = clazz . getInterfaces ( ) ; if ( ifaces != null && ifaces . length > 0 ) Arrays . stream ( ifaces ) . forEach ( iface -> ret . addAll ( allTypeAnnotations ( iface , annotation , recurse ) ) ) ; return ret ; }
Get all annotation on the given class plus all annotations on the parent classes