@Test public void testGetAnnotationFields() { assertNull(ReflectionUtil.getAnnotationFields((Class<?>) null, (Class<? extends Annotation>) null)); assertNull(ReflectionUtil.getAnnotationFields((Class<?>) null, AnnotationClass.TestAnnotation.class)); assertNull(ReflectionUtil.getAnnotationFields(AnnotationClass.class, (Class<? extends Annotation>) null)); Field[] fields = ReflectionUtil.getAnnotationFields(AnnotationClass.class, AnnotationClass.TestAnnotation.class); assertThat(fields.length, is(2)); AnnotationClass.TestAnnotation anno = ReflectionUtil.getAnnotation(fields[0], AnnotationClass.TestAnnotation.class); assertThat(anno.value(), is("y")); fields = ReflectionUtil.getAnnotationFields(AnnotationClass.class, Test.class); assertThat(fields.length, is(0)); }
public static Field[] getAnnotationFields(Class<?> clazz, Class<? extends Annotation> annotationClass) { if (clazz == null || annotationClass == null) { return null; } List<Field> fields = getAllFieldsOfClass0(clazz); if (CollectionUtil.isEmpty(fields)) { return null; } List<Field> list = CollectionUtil.createArrayList(); for (Field field : fields) { if (null != field.getAnnotation(annotationClass)) { list.add(field); field.setAccessible(true); } } return list.toArray(new Field[0]); }
ReflectionUtil { public static Field[] getAnnotationFields(Class<?> clazz, Class<? extends Annotation> annotationClass) { if (clazz == null || annotationClass == null) { return null; } List<Field> fields = getAllFieldsOfClass0(clazz); if (CollectionUtil.isEmpty(fields)) { return null; } List<Field> list = CollectionUtil.createArrayList(); for (Field field : fields) { if (null != field.getAnnotation(annotationClass)) { list.add(field); field.setAccessible(true); } } return list.toArray(new Field[0]); } }
ReflectionUtil { public static Field[] getAnnotationFields(Class<?> clazz, Class<? extends Annotation> annotationClass) { if (clazz == null || annotationClass == null) { return null; } List<Field> fields = getAllFieldsOfClass0(clazz); if (CollectionUtil.isEmpty(fields)) { return null; } List<Field> list = CollectionUtil.createArrayList(); for (Field field : fields) { if (null != field.getAnnotation(annotationClass)) { list.add(field); field.setAccessible(true); } } return list.toArray(new Field[0]); }  }
ReflectionUtil { public static Field[] getAnnotationFields(Class<?> clazz, Class<? extends Annotation> annotationClass) { if (clazz == null || annotationClass == null) { return null; } List<Field> fields = getAllFieldsOfClass0(clazz); if (CollectionUtil.isEmpty(fields)) { return null; } List<Field> list = CollectionUtil.createArrayList(); for (Field field : fields) { if (null != field.getAnnotation(annotationClass)) { list.add(field); field.setAccessible(true); } } return list.toArray(new Field[0]); }  static Field[] getAnnotationFields(Class<?> clazz, Class<? extends Annotation> annotationClass); static A getAnnotation(Field field, Class<A> annotationType); static boolean hasSuperClass(Class<?> clazz); static Method getGetterMethod(Class<?> clazz, Field field); static String getGetterMethodName(Field field); static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes); static T invokeMethod(Method method, Object target, Object... args); }
ReflectionUtil { public static Field[] getAnnotationFields(Class<?> clazz, Class<? extends Annotation> annotationClass) { if (clazz == null || annotationClass == null) { return null; } List<Field> fields = getAllFieldsOfClass0(clazz); if (CollectionUtil.isEmpty(fields)) { return null; } List<Field> list = CollectionUtil.createArrayList(); for (Field field : fields) { if (null != field.getAnnotation(annotationClass)) { list.add(field); field.setAccessible(true); } } return list.toArray(new Field[0]); }  static Field[] getAnnotationFields(Class<?> clazz, Class<? extends Annotation> annotationClass); static A getAnnotation(Field field, Class<A> annotationType); static boolean hasSuperClass(Class<?> clazz); static Method getGetterMethod(Class<?> clazz, Field field); static String getGetterMethodName(Field field); static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes); static T invokeMethod(Method method, Object target, Object... args);  }