use of org.apache.beam.sdk.transforms.reflect.DoFnSignature.FieldAccessDeclaration in project beam by apache.
the class DoFnSignatures method analyzeFieldAccessDeclaration.
private static Map<String, DoFnSignature.FieldAccessDeclaration> analyzeFieldAccessDeclaration(ErrorReporter errors, Class<?> fnClazz) {
Map<String, FieldAccessDeclaration> fieldAccessDeclarations = new HashMap<>();
for (Field field : ReflectHelpers.declaredFieldsWithAnnotation(DoFn.FieldAccess.class, fnClazz, DoFn.class)) {
field.setAccessible(true);
DoFn.FieldAccess fieldAccessAnnotation = field.getAnnotation(DoFn.FieldAccess.class);
if (!Modifier.isFinal(field.getModifiers())) {
errors.throwIllegalArgument("Non-final field %s annotated with %s. Field access declarations must be final.", field.toString(), format(DoFn.FieldAccess.class));
continue;
}
Class<?> fieldAccessRawType = field.getType();
if (!fieldAccessRawType.equals(FieldAccessDescriptor.class)) {
errors.throwIllegalArgument("Field %s annotated with %s, but the value was not of type %s", field.toString(), format(DoFn.FieldAccess.class), format(FieldAccessDescriptor.class));
}
fieldAccessDeclarations.put(fieldAccessAnnotation.value(), FieldAccessDeclaration.create(fieldAccessAnnotation.value(), field));
}
return fieldAccessDeclarations;
}
Aggregations