void validateEnumConstantNameUniqueness(Iterable<Type> nestedTypes) { Multimap<String, EnumType> nameToType = LinkedHashMultimap.create(); for (Type type : nestedTypes) { if (type instanceof EnumType) { EnumType enumType = (EnumType) type; for (EnumConstant enumConstant : enumType.constants()) { nameToType.put(enumConstant.name(), enumType); } } } for (Map.Entry<String, Collection<EnumType>> entry : nameToType.asMap().entrySet()) { if (entry.getValue().size() > 1) { StringBuilder error = new StringBuilder(); String constant = entry.getKey(); int index = 1; error.append(String.format("multiple enums share constant %s:", constant)); for (EnumType enumType : entry.getValue()) { error.append(String.format("\n %s. %s.%s (%s)", index++, enumType.type(), constant, enumType.constant(constant).location())); } addError("%s", error); } } }
@Override public void encode(ProtoWriter writer, Object value) throws IOException { if (value instanceof String) { EnumConstant constant = enumType.constant((String) value); writer.writeVarint32(constant.tag()); } else if (value instanceof Integer) { writer.writeVarint32((Integer) value); } else { throw new IllegalArgumentException("unexpected " + enumType.type() + ": " + value); } }
EnumType enumType = (EnumType) context; error.append(String.format("%s enum %s (%s)", prefix, enumType.type(), enumType.location()));
NameAllocator nameAllocator = nameAllocators.getUnchecked(type); String value = nameAllocator.get("value"); ClassName javaType = (ClassName) typeName(type.type());
void validateEnumConstantNameUniqueness(Iterable<Type> nestedTypes) { Multimap<String, EnumType> nameToType = LinkedHashMultimap.create(); for (Type type : nestedTypes) { if (type instanceof EnumType) { EnumType enumType = (EnumType) type; for (EnumConstant enumConstant : enumType.constants()) { nameToType.put(enumConstant.name(), enumType); } } } for (Map.Entry<String, Collection<EnumType>> entry : nameToType.asMap().entrySet()) { if (entry.getValue().size() > 1) { StringBuilder error = new StringBuilder(); String constant = entry.getKey(); int index = 1; error.append(String.format("multiple enums share constant %s:", constant)); for (EnumType enumType : entry.getValue()) { error.append(String.format("\n %s. %s.%s (%s)", index++, enumType.type(), constant, enumType.constant(constant).location())); } addError("%s", error); } } }
void validateEnumConstantNameUniqueness(Iterable<Type> nestedTypes) { Multimap<String, EnumType> nameToType = LinkedHashMultimap.create(); for (Type type : nestedTypes) { if (type instanceof EnumType) { EnumType enumType = (EnumType) type; for (EnumConstant enumConstant : enumType.constants()) { nameToType.put(enumConstant.name(), enumType); } } } for (Map.Entry<String, Collection<EnumType>> entry : nameToType.asMap().entrySet()) { if (entry.getValue().size() > 1) { StringBuilder error = new StringBuilder(); String constant = entry.getKey(); int index = 1; error.append(String.format("multiple enums share constant %s:", constant)); for (EnumType enumType : entry.getValue()) { error.append(String.format("\n %s. %s.%s (%s)", index++, enumType.type(), constant, enumType.constant(constant).location())); } addError("%s", error); } } }
@Override public void encode(ProtoWriter writer, Object value) throws IOException { if (value instanceof String) { EnumConstant constant = enumType.constant((String) value); writer.writeVarint32(constant.tag()); } else if (value instanceof Integer) { writer.writeVarint32((Integer) value); } else { throw new IllegalArgumentException("unexpected " + enumType.type() + ": " + value); } }
@Override public void encode(ProtoWriter writer, Object value) throws IOException { if (value instanceof String) { EnumConstant constant = enumType.constant((String) value); writer.writeVarint32(constant.tag()); } else if (value instanceof Integer) { writer.writeVarint32((Integer) value); } else { throw new IllegalArgumentException("unexpected " + enumType.type() + ": " + value); } }
EnumType enumType = (EnumType) context; error.append(String.format("%s enum %s (%s)", prefix, enumType.type(), enumType.location()));
EnumType enumType = (EnumType) context; error.append(String.format("%s enum %s (%s)", prefix, enumType.type(), enumType.location()));
public TypeSpec generateEnum(EnumType type) { ClassName javaType = (ClassName) typeName(type.type());
ClassName javaType = (ClassName) typeName(type.type());