public static Set<Annotation> getAllAnnotations(Method m) {
        Set<Annotation> annotationSet = new LinkedHashSet<Annotation>();
        Annotation[] annotations = m.getAnnotations();
        List<Class<?>> annotationTypes = new ArrayList<Class<?>>();

        // Iterate through all annotations of the current class
        for (Annotation a : annotations) {
            // Add the current annotation to the result and to the annotation types that needed to be examained for stereotype annotations
            annotationSet.add(a);
            annotationTypes.add(a.annotationType());
        }

        if (stereotypeAnnotationClass != null) {
            while (!annotationTypes.isEmpty()) {
                Class<?> annotationType = annotationTypes.remove(annotationTypes.size() - 1);

                if (annotationType.isAnnotationPresent(stereotypeAnnotationClass)) {
                    // If the stereotype annotation is present examine the 'inherited' annotations
                    for (Annotation annotation : annotationType.getAnnotations()) {
                        // add the 'inherited' annotations to be examined for further stereotype annotations
                        annotationTypes.add(annotation.annotationType());

                        if (!annotation.annotationType().equals(stereotypeAnnotationClass)) {
                            // add the stereotyped annotations to the set
                            annotationSet.add(annotation);
                        }
                    }
                }
            }
        }

        return annotationSet;
    }
public static Set < Annotation > getAllAnnotations ( Method m ) { Set < Annotation > annotationSet = new LinkedHashSet < Annotation > ( ) ; Annotation [ ] annotations = m . getAnnotations ( ) ; List < Class < ? > > annotationTypes = new ArrayList < Class < ? > > ( ) ; for ( Annotation a : annotations ) { annotationSet . add ( a ) ; annotationTypes . add ( a . annotationType ( ) ) ; } if ( stereotypeAnnotationClass != null ) { while ( ! annotationTypes . isEmpty ( ) ) { Class < ? > annotationType = annotationTypes . remove ( annotationTypes . size ( ) - 1 ) ; if ( annotationType . isAnnotationPresent ( stereotypeAnnotationClass ) ) { for ( Annotation annotation : annotationType . getAnnotations ( ) ) { annotationTypes . add ( annotation . annotationType ( ) ) ; if ( ! annotation . annotationType ( ) . equals ( stereotypeAnnotationClass ) ) { annotationSet . add ( annotation ) ; } } } } } return annotationSet ; }
Returns all annotations of a class, also the annotations of the super
classes, implemented interfaces and the annotations that are present in
stereotype annotations. The stereotype annotation will not be included in
the annotation set.

@param m the class from which to get the annotations
@return all annotations that are present for the given class