public static Collection < Method > findAnnotatedMethods ( Class < ? > type , Class < ? extends Annotation > annotation ) { List < Method > result = new ArrayList <> ( ) ; // gather all publicly available methods // this returns everything, even if it's declared in a parent for ( Method method : type . getMethods ( ) ) { // skip methods that are used internally by the vm for implementing covariance, etc if ( method . isSynthetic ( ) || method . isBridge ( ) || isStatic ( method . getModifiers ( ) ) ) { continue ; } // look for annotations recursively in super-classes or interfaces Method managedMethod = findAnnotatedMethod ( type , annotation , method . getName ( ) , method . getParameterTypes ( ) ) ; if ( managedMethod != null ) { result . add ( managedMethod ) ; } } return result ; }
Find methods that are tagged with a given annotation somewhere in the hierarchy