Search in sources :

Example 1 with FieldAccessDeclaration

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;
}
Also used : Field(java.lang.reflect.Field) FieldAccessDescriptor(org.apache.beam.sdk.schemas.FieldAccessDescriptor) DoFn(org.apache.beam.sdk.transforms.DoFn) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormatString(com.google.errorprone.annotations.FormatString) FieldAccessDeclaration(org.apache.beam.sdk.transforms.reflect.DoFnSignature.FieldAccessDeclaration)

Aggregations

FormatString (com.google.errorprone.annotations.FormatString)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 FieldAccessDescriptor (org.apache.beam.sdk.schemas.FieldAccessDescriptor)1 DoFn (org.apache.beam.sdk.transforms.DoFn)1 FieldAccessDeclaration (org.apache.beam.sdk.transforms.reflect.DoFnSignature.FieldAccessDeclaration)1