use of com.squareup.wire.schema.internal.parser.EnumConstantElement in project apicurio-registry by Apicurio.
the class ProtobufFile method processEnumElement.
private void processEnumElement(String scope, EnumElement enumElement) {
// TODO reservedEnumFields - wire doesn't preserve these
// https://github.com/square/wire/issues/797 RFE: capture EnumElement reserved info
// enumFieldMap, enumFieldsIDName, nonReservedEnumFields
Map<String, EnumConstantElement> map = new HashMap<>();
Map<Integer, String> idsToNames = new HashMap<>();
Set<Object> fieldKeySet = new HashSet<>();
for (EnumConstantElement enumConstantElement : enumElement.getConstants()) {
map.put(enumConstantElement.getName(), enumConstantElement);
idsToNames.put(enumConstantElement.getTag(), enumConstantElement.getName());
fieldKeySet.add(enumConstantElement.getTag());
fieldKeySet.add(enumConstantElement.getName());
}
if (!map.isEmpty()) {
enumFieldMap.put(scope + enumElement.getName(), map);
}
if (!idsToNames.isEmpty()) {
enumFieldsById.put(scope + enumElement.getName(), idsToNames);
}
if (!fieldKeySet.isEmpty()) {
nonReservedEnumFields.put(scope + enumElement.getName(), fieldKeySet);
}
}
use of com.squareup.wire.schema.internal.parser.EnumConstantElement in project aws-glue-schema-registry by awslabs.
the class FileDescriptorUtils method toEnum.
private static EnumElement toEnum(EnumDescriptorProto ed) {
String name = ed.getName();
ImmutableList.Builder<EnumConstantElement> constants = ImmutableList.builder();
for (EnumValueDescriptorProto ev : ed.getValueList()) {
ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
constants.add(new EnumConstantElement(DEFAULT_LOCATION, ev.getName(), ev.getNumber(), "", options.build()));
}
ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
if (ed.getOptions().hasAllowAlias()) {
OptionElement option = new OptionElement(ALLOW_ALIAS_OPTION, booleanKind, ed.getOptions().getAllowAlias(), false);
options.add(option);
}
return new EnumElement(DEFAULT_LOCATION, name, "", options.build(), constants.build());
}
use of com.squareup.wire.schema.internal.parser.EnumConstantElement in project aws-glue-schema-registry by awslabs.
the class ProtobufFile method processEnumElement.
private void processEnumElement(String scope, EnumElement enumElement) {
// TODO reservedEnumFields - wire doesn't preserve these
// https://github.com/square/wire/issues/797 RFE: capture EnumElement reserved info
// enumFieldMap, enumFieldsIDName, nonReservedEnumFields
Map<String, EnumConstantElement> map = new HashMap<>();
Map<Integer, String> idsToNames = new HashMap<>();
Set<Object> fieldKeySet = new HashSet<>();
for (EnumConstantElement enumConstantElement : enumElement.getConstants()) {
map.put(enumConstantElement.getName(), enumConstantElement);
idsToNames.put(enumConstantElement.getTag(), enumConstantElement.getName());
fieldKeySet.add(enumConstantElement.getTag());
fieldKeySet.add(enumConstantElement.getName());
}
if (!map.isEmpty()) {
enumFieldMap.put(scope + enumElement.getName(), map);
}
if (!idsToNames.isEmpty()) {
enumFieldsById.put(scope + enumElement.getName(), idsToNames);
}
if (!fieldKeySet.isEmpty()) {
nonReservedEnumFields.put(scope + enumElement.getName(), fieldKeySet);
}
}
use of com.squareup.wire.schema.internal.parser.EnumConstantElement in project schema-registry by confluentinc.
the class ProtobufSchema method toEnum.
private static EnumElement toEnum(EnumDescriptorProto ed) {
String name = ed.getName();
log.trace("*** enum name: {}", name);
ImmutableList.Builder<EnumConstantElement> constants = ImmutableList.builder();
for (EnumValueDescriptorProto ev : ed.getValueList()) {
ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
if (ev.getOptions().hasDeprecated()) {
OptionElement option = new OptionElement(DEPRECATED, Kind.BOOLEAN, ev.getOptions().getDeprecated(), false);
options.add(option);
}
if (ev.getOptions().hasExtension(MetaProto.enumValueMeta)) {
Meta meta = ev.getOptions().getExtension(MetaProto.enumValueMeta);
OptionElement option = toOption(CONFLUENT_ENUM_VALUE_META, meta);
if (option != null) {
options.add(option);
}
}
constants.add(new EnumConstantElement(DEFAULT_LOCATION, ev.getName(), ev.getNumber(), "", options.build()));
}
ImmutableList.Builder<ReservedElement> reserved = ImmutableList.builder();
for (EnumReservedRange range : ed.getReservedRangeList()) {
ReservedElement reservedElem = toReserved(range);
reserved.add(reservedElem);
}
for (String reservedName : ed.getReservedNameList()) {
ReservedElement reservedElem = new ReservedElement(DEFAULT_LOCATION, "", Collections.singletonList(reservedName));
reserved.add(reservedElem);
}
ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
if (ed.getOptions().hasAllowAlias()) {
OptionElement option = new OptionElement(ALLOW_ALIAS, Kind.BOOLEAN, ed.getOptions().getAllowAlias(), false);
options.add(option);
}
if (ed.getOptions().hasDeprecated()) {
OptionElement option = new OptionElement(DEPRECATED, Kind.BOOLEAN, ed.getOptions().getDeprecated(), false);
options.add(option);
}
if (ed.getOptions().hasExtension(MetaProto.enumMeta)) {
Meta meta = ed.getOptions().getExtension(MetaProto.enumMeta);
OptionElement option = toOption(CONFLUENT_ENUM_META, meta);
if (option != null) {
options.add(option);
}
}
return new EnumElement(DEFAULT_LOCATION, name, "", options.build(), constants.build(), reserved.build());
}
use of com.squareup.wire.schema.internal.parser.EnumConstantElement in project schema-registry by confluentinc.
the class ProtobufSchema method toDynamicEnum.
private static EnumDefinition toDynamicEnum(EnumElement enumElem) {
Map<String, OptionElement> enumOptions = mergeOptions(enumElem.getOptions());
Boolean allowAlias = findOption(ALLOW_ALIAS, enumOptions).map(o -> Boolean.valueOf(o.getValue().toString())).orElse(null);
Boolean isDeprecated = findOption(DEPRECATED, enumOptions).map(o -> Boolean.valueOf(o.getValue().toString())).orElse(null);
EnumDefinition.Builder enumer = EnumDefinition.newBuilder(enumElem.getName(), allowAlias, isDeprecated);
for (ReservedElement reserved : enumElem.getReserveds()) {
for (Object elem : reserved.getValues()) {
if (elem instanceof String) {
enumer.addReservedName((String) elem);
} else if (elem instanceof Integer) {
int tag = (Integer) elem;
enumer.addReservedRange(tag, tag + 1);
} else if (elem instanceof IntRange) {
IntRange range = (IntRange) elem;
enumer.addReservedRange(range.getStart(), range.getEndInclusive() + 1);
} else {
throw new IllegalStateException("Unsupported reserved type: " + elem.getClass().getName());
}
}
}
for (EnumConstantElement constant : enumElem.getConstants()) {
Map<String, OptionElement> constantOptions = mergeOptions(constant.getOptions());
Boolean isConstDeprecated = findOption(DEPRECATED, constantOptions).map(o -> Boolean.valueOf(o.getValue().toString())).orElse(null);
Optional<OptionElement> meta = findOption(CONFLUENT_ENUM_VALUE_META, constantOptions);
String doc = findDoc(meta);
Map<String, String> params = findParams(meta);
enumer.addValue(constant.getName(), constant.getTag(), doc, params, isConstDeprecated);
}
Optional<OptionElement> meta = findOption(CONFLUENT_ENUM_META, enumOptions);
String doc = findDoc(meta);
Map<String, String> params = findParams(meta);
enumer.setMeta(doc, params);
return enumer.build();
}
Aggregations