AnnotationUtils { public static <T extends Annotation> List<T> findNestedAnnotations(AnnotatedElement annotatedElement, Class<T> annotationType) { List<T> nestedAnnotations = new ArrayList<T>(); if (annotatedElement.isAnnotationPresent(annotationType)) { nestedAnnotations.add(annotatedElement.getAnnotation(annotationType)); } for (Annotation annotation : annotatedElement.getAnnotations()) { T searchedAnnotation = findAnnotation(annotation, annotationType); if (searchedAnnotation != null) { nestedAnnotations.add(searchedAnnotation); } } return nestedAnnotations; } private  AnnotationUtils(); static List<T> findNestedAnnotations(AnnotatedElement annotatedElement, Class<T> annotationType); @SuppressWarnings("unchecked") static T findAnnotation(Annotation parentAnnotation, Class<T> annotationType);  }
@Test public void testFindNestedAnnotationsInClass() throws Exception { List<Intercept> interceptAnnotations = AnnotationUtils.findNestedAnnotations(SimpleActionClass.class, Intercept.class); assertEquals(1, interceptAnnotations.size()); }
@Test public void testFindNestedAnnotationsInMethod() throws Exception { Method action = SimpleActionClass.class.getDeclaredMethod("nonDefaultAction", String.class); List<Intercept> interceptAnnotations = AnnotationUtils.findNestedAnnotations(action, Intercept.class); assertEquals(1, interceptAnnotations.size()); }