@Test void ofWrongTypeThrowsException() { calling(() -> FieldInfo.of(ClassWithField.class, "string", Integer.class)) .shouldThrow(NoSuchElementException.class) .withMessage(is("No field called string of type class java.lang.Integer in class com.cadenzauk.core.reflect.FieldInfoTest$ClassWithField")); }
@SuppressWarnings("unchecked") public static <R> FieldInfo<R,?> of(Class<R> declaringClass, Field field) { if (field.getType() == Optional.class) { return genericTypeArgument(field, 0) .map(cls -> of(declaringClass, field, cls)) .orElseThrow(() -> new IllegalArgumentException("Unable to determine the type of Optional field " + field.getName() + " in " + declaringClass)); } return of(declaringClass, field, field.getType()); }
FieldInfo { @SuppressWarnings("unchecked") public static <R> FieldInfo<R,?> of(Class<R> declaringClass, Field field) { if (field.getType() == Optional.class) { return genericTypeArgument(field, 0) .map(cls -> of(declaringClass, field, cls)) .orElseThrow(() -> new IllegalArgumentException("Unable to determine the type of Optional field " + field.getName() + " in " + declaringClass)); } return of(declaringClass, field, field.getType()); } }
FieldInfo { @SuppressWarnings("unchecked") public static <R> FieldInfo<R,?> of(Class<R> declaringClass, Field field) { if (field.getType() == Optional.class) { return genericTypeArgument(field, 0) .map(cls -> of(declaringClass, field, cls)) .orElseThrow(() -> new IllegalArgumentException("Unable to determine the type of Optional field " + field.getName() + " in " + declaringClass)); } return of(declaringClass, field, field.getType()); } private  FieldInfo(TypeToken<C> declaringType, Field field, Class<F> effectiveType); }
FieldInfo { @SuppressWarnings("unchecked") public static <R> FieldInfo<R,?> of(Class<R> declaringClass, Field field) { if (field.getType() == Optional.class) { return genericTypeArgument(field, 0) .map(cls -> of(declaringClass, field, cls)) .orElseThrow(() -> new IllegalArgumentException("Unable to determine the type of Optional field " + field.getName() + " in " + declaringClass)); } return of(declaringClass, field, field.getType()); } private  FieldInfo(TypeToken<C> declaringType, Field field, Class<F> effectiveType); @Override String toString(); TypeToken<C> declaringType(); @SuppressWarnings("unchecked") Class<C> declaringClass(); Field field(); String name(); Class<?> fieldType(); Class<F> effectiveClass(); TypeToken<F> effectiveType(); FunctionOptional1<C, F> optionalGetter(); boolean hasAnnotation(Class<A> annotation); Optional<A> annotation(Class<A> annotation); @SuppressWarnings("unchecked") static FieldInfo<R,?> of(Class<R> declaringClass, Field field); @SuppressWarnings("unchecked") static FieldInfo<R,?> of(TypeToken<R> declaringClass, Field field); static FieldInfo<R,T> of(Class<R> rowClass, Field field, Class<T> fieldType); static FieldInfo<R,T> of(TypeToken<R> rowClass, Field field, Class<T> fieldType); static FieldInfo<C,F> of(Class<C> objectClass, String fieldName, Class<F> fieldType); static Optional<FieldInfo<C,F>> ofGetter(MethodInfo<C,F> getter); }
FieldInfo { @SuppressWarnings("unchecked") public static <R> FieldInfo<R,?> of(Class<R> declaringClass, Field field) { if (field.getType() == Optional.class) { return genericTypeArgument(field, 0) .map(cls -> of(declaringClass, field, cls)) .orElseThrow(() -> new IllegalArgumentException("Unable to determine the type of Optional field " + field.getName() + " in " + declaringClass)); } return of(declaringClass, field, field.getType()); } private  FieldInfo(TypeToken<C> declaringType, Field field, Class<F> effectiveType); @Override String toString(); TypeToken<C> declaringType(); @SuppressWarnings("unchecked") Class<C> declaringClass(); Field field(); String name(); Class<?> fieldType(); Class<F> effectiveClass(); TypeToken<F> effectiveType(); FunctionOptional1<C, F> optionalGetter(); boolean hasAnnotation(Class<A> annotation); Optional<A> annotation(Class<A> annotation); @SuppressWarnings("unchecked") static FieldInfo<R,?> of(Class<R> declaringClass, Field field); @SuppressWarnings("unchecked") static FieldInfo<R,?> of(TypeToken<R> declaringClass, Field field); static FieldInfo<R,T> of(Class<R> rowClass, Field field, Class<T> fieldType); static FieldInfo<R,T> of(TypeToken<R> rowClass, Field field, Class<T> fieldType); static FieldInfo<C,F> of(Class<C> objectClass, String fieldName, Class<F> fieldType); static Optional<FieldInfo<C,F>> ofGetter(MethodInfo<C,F> getter);  }