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;
}
Aggregations