ReflectionUtils { public static List<Field> getAllDeclaredFieldsAnnotatedWith(Class<?> type, Class<? extends Annotation> annotationType) { List<Field> fields = ReflectionUtils.getAllDeclaredFields(type); filterByAnnotationType(fields, annotationType); return fields; } private  ReflectionUtils(); static List<Method> findMethods(Class<?> clazz, String nameRegex,
            ParamCount numberOfParams); static List<Method> findMethods(Class<?> clazz, String nameRegex,
            Class<?>... paramTypes); static boolean isComponent(Class<?> componentClass); static List<Field> getAllDeclaredFields(Class<?> type); static List<Field> getAllDeclaredFieldsAnnotatedWith(Class<?> type,
            Class<? extends Annotation> annotationType); static List<Method> getAllDeclaredMethods(Class<?> type); static List<Method> getAllDeclaredMethodsAnnotatedWith(Class<?> type,
            Class<? extends Annotation> annotationType);  }
@Test public void test_getAllDeclaredFieldsFromBaseClassByAnnotation() { List<Field> fields = getAllDeclaredFieldsAnnotatedWith( BaseClassToExamine.class, UiField.class); assertEquals(1, fields.size()); assertEquals("textFieldBase", fields.get(0).getName()); }
@Test public void test_getAllDeclaredFieldsFromSubClassByAnnotation() { List<Field> fields = getAllDeclaredFieldsAnnotatedWith( SubClassToExamine.class, UiField.class); assertEquals(2, fields.size()); Collections.sort(fields, new FieldByNameComparator()); assertEquals("textFieldBase", fields.get(0).getName()); assertEquals("textFieldSub", fields.get(1).getName()); }