@Test void ofGetter() { FieldInfo<ClassWithField,String> fieldInfo = FieldInfo.ofGetter(MethodInfo.of(ClassWithField::string)) .orElseThrow(() -> new AssertionError("Should have got FieldInfo for string but didn't")); assertThat(fieldInfo.declaringType(), equalTo(TypeToken.of(ClassWithField.class))); assertThat(fieldInfo.declaringClass(), equalTo(ClassWithField.class)); assertThat(fieldInfo.name(), equalTo("string")); assertThat(fieldInfo.fieldType(), equalTo(String.class)); assertThat(fieldInfo.effectiveClass(), equalTo(String.class)); }
public static <C, F> Optional<FieldInfo<C,F>> ofGetter(MethodInfo<C,F> getter) { return Arrays.stream(getter.referringClass().getDeclaredFields()) .filter(f -> getter.actualType().isAssignableFrom(f.getType())) .filter(f -> Getter.isGetter(getter.method(), f)) .findAny() .map(f -> of(getter.referringClass(), f, getter.effectiveClass())); }
FieldInfo { public static <C, F> Optional<FieldInfo<C,F>> ofGetter(MethodInfo<C,F> getter) { return Arrays.stream(getter.referringClass().getDeclaredFields()) .filter(f -> getter.actualType().isAssignableFrom(f.getType())) .filter(f -> Getter.isGetter(getter.method(), f)) .findAny() .map(f -> of(getter.referringClass(), f, getter.effectiveClass())); } }
FieldInfo { public static <C, F> Optional<FieldInfo<C,F>> ofGetter(MethodInfo<C,F> getter) { return Arrays.stream(getter.referringClass().getDeclaredFields()) .filter(f -> getter.actualType().isAssignableFrom(f.getType())) .filter(f -> Getter.isGetter(getter.method(), f)) .findAny() .map(f -> of(getter.referringClass(), f, getter.effectiveClass())); } private  FieldInfo(TypeToken<C> declaringType, Field field, Class<F> effectiveType); }
FieldInfo { public static <C, F> Optional<FieldInfo<C,F>> ofGetter(MethodInfo<C,F> getter) { return Arrays.stream(getter.referringClass().getDeclaredFields()) .filter(f -> getter.actualType().isAssignableFrom(f.getType())) .filter(f -> Getter.isGetter(getter.method(), f)) .findAny() .map(f -> of(getter.referringClass(), f, getter.effectiveClass())); } 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 { public static <C, F> Optional<FieldInfo<C,F>> ofGetter(MethodInfo<C,F> getter) { return Arrays.stream(getter.referringClass().getDeclaredFields()) .filter(f -> getter.actualType().isAssignableFrom(f.getType())) .filter(f -> Getter.isGetter(getter.method(), f)) .findAny() .map(f -> of(getter.referringClass(), f, getter.effectiveClass())); } 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);  }