public ClassIntrospector(Class<?> clazz) { this.clazz = clazz; fields = findFields(clazz); }
@SuppressWarnings("unchecked") private BeanInstance(T instance) { this.type = (Class<T>) instance.getClass(); this.instance = instance; List<Field> fields = findFields(type); fieldAnnotations = findFieldsAnnotations(fields); }
private static String getIdField(Class<?> clazz) { for (Field field : findFields(clazz)) { field.setAccessible(true); Annotation annotation = field.getAnnotation(Id.class); if (annotation != null) { return field.getName(); } } throw new RuntimeException("Class [" + clazz + "] does not decalare @Id."); }
private void inject(Object instance, Map<String, Object> values) { List<Field> fields = findFields(instance.getClass()); for (Field field : fields) { field.setAccessible(true); Object value = values.get(field.getName()); if (value == null) { continue; } try { field.set(instance, value); } catch (IllegalArgumentException e) { throw new UnsupportedOperationException(e); } catch (IllegalAccessException e) { throw new UnsupportedOperationException(e); } } }
private Set<Class<?>> getTransitiveDependencies(Class<?> clazz) { Set<Class<?>> transitive = new HashSet<Class<?>>(); transitive.addAll(getAnnotationDependencies(clazz.getAnnotations())); for (Field f : findFields(clazz)) { transitive.addAll(getAnnotationDependencies(f.getAnnotations())); } return transitive; }
private Set<Class<?>> getTransitiveDependencies(Class<?> clazz) { Set<Class<?>> transitive = new HashSet<Class<?>>(); transitive.addAll(getSuperClasses(clazz)); for (Field f : findFields(clazz)) { transitive.addAll(getEnumDependencies(f)); } return transitive; }