@Test public void testGetAllFieldsByAnnotation() throws SecurityException { int i = 0; Collection<Field> fields; final String[] injectedFieldNames = { "publicValue2", "protectedValue2", "packageValue2", "privateValue2" }; fields = ClassUtil.getAllFields(MyBean.class, Inject.class); assertEquals(injectedFieldNames.length, fields.size()); for (final Field field : fields) { assertEquals(injectedFieldNames[i], field.getName()); i++; } i = 0; final String[] deprectatedFieldNames = { "publicValue1" }; fields = ClassUtil.getAllFields(MyBean.class, Deprecated.class); assertEquals(deprectatedFieldNames.length, fields.size()); for (final Field field : fields) { assertEquals(deprectatedFieldNames[i], field.getName()); i++; } i = 0; final String[] injectedFieldNames2 = { "privateValue4", "publicValue2", "protectedValue2", "packageValue2", "privateValue2" }; fields = ClassUtil.getAllFields(MySubBean.class, Inject.class); assertEquals(injectedFieldNames2.length, fields.size()); for (final Field field : fields) { assertEquals(injectedFieldNames2[i], field.getName()); i++; } }
public static Collection<Field> getAllFields(final Class<?> clazz, final Class<? extends Annotation> annotation) { Assertion.check() .isNotNull(clazz) .isNotNull(annotation); return ClassUtil.getAllFields(clazz) .stream() .filter(field -> field.isAnnotationPresent(annotation)) .collect(Collectors.toList()); }
ClassUtil { public static Collection<Field> getAllFields(final Class<?> clazz, final Class<? extends Annotation> annotation) { Assertion.check() .isNotNull(clazz) .isNotNull(annotation); return ClassUtil.getAllFields(clazz) .stream() .filter(field -> field.isAnnotationPresent(annotation)) .collect(Collectors.toList()); } }
ClassUtil { public static Collection<Field> getAllFields(final Class<?> clazz, final Class<? extends Annotation> annotation) { Assertion.check() .isNotNull(clazz) .isNotNull(annotation); return ClassUtil.getAllFields(clazz) .stream() .filter(field -> field.isAnnotationPresent(annotation)) .collect(Collectors.toList()); } private  ClassUtil(); }
ClassUtil { public static Collection<Field> getAllFields(final Class<?> clazz, final Class<? extends Annotation> annotation) { Assertion.check() .isNotNull(clazz) .isNotNull(annotation); return ClassUtil.getAllFields(clazz) .stream() .filter(field -> field.isAnnotationPresent(annotation)) .collect(Collectors.toList()); } private  ClassUtil(); static Object newInstance(final String javaClassName); static J newInstance(final String javaClassName, final Class<J> type); static J newInstance(final Class<J> clazz); static J newInstance(final Constructor<J> constructor, final Object[] args); static Constructor<J> findConstructor(final Class<J> clazz, final Class<?>[] parameterTypes); static Class<?> classForName(final String javaClassName); static Class<? extends J> classForName(final String javaClassName, final Class<J> type); static Object invoke(final Object instance, final Method method, final Object... args); static void set(final Object instance, final Field field, final Object value); static Object get(final Object instance, final Field field); static Method findMethod(final Class<?> clazz, final String methodName, final Class<?>... parameterTypes); static Collection<Field> getAllFields(final Class<?> clazz, final Class<? extends Annotation> annotation); static Collection<Method> getAllMethods(final Class<?> clazz, final Class<? extends Annotation> annotation); static Collection<Field> getAllFields(final Class<?> clazz); static Collection<Method> getAllMethods(final Class<?> clazz); static Set<Class<?>> getAllInterfaces(final Class<?> clazz); static Class<?> getGeneric(final Constructor<?> constructor, final int i); static Class<?> getGeneric(final Method method, final int i); static Class<?> getGeneric(final Field field); static Class<?> getGeneric(
			final Type type,
			final Supplier<RuntimeException> exceptionSupplier); static String getPropertyName(final Method method); }
ClassUtil { public static Collection<Field> getAllFields(final Class<?> clazz, final Class<? extends Annotation> annotation) { Assertion.check() .isNotNull(clazz) .isNotNull(annotation); return ClassUtil.getAllFields(clazz) .stream() .filter(field -> field.isAnnotationPresent(annotation)) .collect(Collectors.toList()); } private  ClassUtil(); static Object newInstance(final String javaClassName); static J newInstance(final String javaClassName, final Class<J> type); static J newInstance(final Class<J> clazz); static J newInstance(final Constructor<J> constructor, final Object[] args); static Constructor<J> findConstructor(final Class<J> clazz, final Class<?>[] parameterTypes); static Class<?> classForName(final String javaClassName); static Class<? extends J> classForName(final String javaClassName, final Class<J> type); static Object invoke(final Object instance, final Method method, final Object... args); static void set(final Object instance, final Field field, final Object value); static Object get(final Object instance, final Field field); static Method findMethod(final Class<?> clazz, final String methodName, final Class<?>... parameterTypes); static Collection<Field> getAllFields(final Class<?> clazz, final Class<? extends Annotation> annotation); static Collection<Method> getAllMethods(final Class<?> clazz, final Class<? extends Annotation> annotation); static Collection<Field> getAllFields(final Class<?> clazz); static Collection<Method> getAllMethods(final Class<?> clazz); static Set<Class<?>> getAllInterfaces(final Class<?> clazz); static Class<?> getGeneric(final Constructor<?> constructor, final int i); static Class<?> getGeneric(final Method method, final int i); static Class<?> getGeneric(final Field field); static Class<?> getGeneric(
			final Type type,
			final Supplier<RuntimeException> exceptionSupplier); static String getPropertyName(final Method method);  }