public static Field[] getAllFields(final Class<?> clazz, final Class<? extends Annotation> withAnnotation) { final List<Field> result = new ArrayList<>(); final Field[] fields = getAllFields(clazz); for (final Field field : fields) { if (isAnnotationPresent(field, withAnnotation)) { result.add(field); } } return result.toArray(new Field[result.size()]); }
public void initialize(final Converter<?> converter, final InjectionManager injectionManager) { if (injectionManager != null) { final Field[] fields = ReflectionUtils.getAllFields(converter.getClass(), Inject.class); for (final Field field : fields) { final Object value; if (field.getType() == Converter.class) { // Injected converters are used as callbacks. They // should be assigned to the outer converter, which is // this. value = this; } else { final InjectionPoint<Object> injectionPoint = new MemberInjectionPoint<>(field, converter); value = injectionManager.getInstance(injectionPoint); } field.setAccessible(true); try { field.set(converter, value); } catch (final Exception e) { throw new IllegalStateException("Could not initialize converter: " + converter, e); } } } }
protected void visitClass() { final Field[] fields = ReflectionUtils.getAllFields(_componentClass); for (final Field field : fields) { visitField(field); } final Method[] methods = ReflectionUtils.getMethods(_componentClass); for (final Method method : methods) { visitMethod(method); } }
public void readObject(final ObjectInputStream stream, final Adaptor adaptor) throws IOException, ClassNotFoundException { try { final GetField getField = stream.readFields(); Field[] fields; fields = _clazz.getDeclaredFields(); deserializeFields(fields, getField); fields = ReflectionUtils.getAllFields(_clazz, Moved.class); deserializeFields(fields, getField); if (adaptor != null) { adaptor.deserialize(getField, _serializable); } } catch (final Exception e) { logger.error("Could not deserialize object!", e); if (e instanceof IOException) { throw (IOException) e; } if (e instanceof ClassNotFoundException) { throw (ClassNotFoundException) e; } throw new RuntimeException(e); } }