Search in sources :

Example 1 with PRequirement

use of net.morimekta.providence.descriptor.PRequirement in project providence by morimekta.

the class ProgramConverter method makeField.

private CField makeField(TypeRegistry registry, String pkg, FieldType field, MessageVariant variant) {
    PDescriptorProvider type = registry.getProvider(field.getType(), pkg, field.getAnnotations());
    ConstProvider defaultValue = null;
    if (field.hasDefaultValue()) {
        defaultValue = new ConstProvider(registry, field.getType(), pkg, field.getDefaultValue(), field.getStartLineNo(), field.getStartLinePos());
    }
    PRequirement requirement = PRequirement.valueOf(field.getRequirement().asString());
    if (variant == MessageVariant.UNION) {
        if (requirement == PRequirement.REQUIRED) {
            throw new IllegalArgumentException("Required field in union");
        }
        requirement = PRequirement.OPTIONAL;
    }
    @SuppressWarnings("unchecked") CField made = new CField(field.getDocumentation(), field.getId(), requirement, field.getName(), type, defaultValue, field.getAnnotations());
    return made;
}
Also used : PRequirement(net.morimekta.providence.descriptor.PRequirement) CField(net.morimekta.providence.reflect.contained.CField) PDescriptorProvider(net.morimekta.providence.descriptor.PDescriptorProvider)

Aggregations

PDescriptorProvider (net.morimekta.providence.descriptor.PDescriptorProvider)1 PRequirement (net.morimekta.providence.descriptor.PRequirement)1 CField (net.morimekta.providence.reflect.contained.CField)1