private void validateTagUniqueness(Linker linker) { Multimap<Integer, EnumConstant> tagToConstant = LinkedHashMultimap.create(); for (EnumConstant constant : constants) { tagToConstant.put(constant.tag(), constant); } for (Map.Entry<Integer, Collection<EnumConstant>> entry : tagToConstant.asMap().entrySet()) { if (entry.getValue().size() > 1) { StringBuilder error = new StringBuilder(); error.append(String.format("multiple enum constants share tag %s:", entry.getKey())); int index = 1; for (EnumConstant constant : entry.getValue()) { error.append(String.format("\n %s. %s (%s)", index++, constant.name(), constant.location())); } linker.addError("%s", error); } } }
/** Combine values for the same key, resolving conflicts based on their type. */ @SuppressWarnings("unchecked") private Object union(Linker linker, Object a, Object b) { if (a instanceof List) { return union((List<?>) a, (List<?>) b); } else if (a instanceof Map) { return union(linker, (Map<ProtoMember, Object>) a, (Map<ProtoMember, Object>) b); } else { linker.addError("conflicting options: %s, %s", a, b); return a; // Just return any placeholder. } }
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 validate(Linker linker) { linker = linker.withContext(this); if (isPacked() && !isPackable(linker, type)) { linker.addError("packed=true not permitted on %s", type); } if (extension && isRequired()) { linker.addError("extension fields cannot be required", type); } linker.validateImport(location(), type); }
int tag = field.tag(); if (!Util.isValidTag(tag)) { withContext(field).addError("tag is out of range: %s", tag); withContext(field).addError("tag %s is reserved (%s)", tag, reserved.location()); withContext(field).addError("name '%s' is reserved (%s)", field.name(), reserved.location()); index++, field.name(), field.location())); addError("%s", error); index++, field.name(), field.location())); addError("%s", error);
private ProtoType resolveType(String name, boolean messageOnly) { ProtoType type = ProtoType.get(name); if (type.isScalar()) { if (messageOnly) { addError("expected a message but was %s", name); } return type; } if (type.isMap()) { if (messageOnly) { addError("expected a message but was %s", name); } ProtoType keyType = resolveType(type.keyType().toString(), false); ProtoType valueType = resolveType(type.valueType().toString(), false); return new ProtoType(keyType, valueType, name); } Type resolved = resolve(name, protoTypeNames); if (resolved == null) { addError("unable to resolve %s", name); return ProtoType.BYTES; // Just return any placeholder. } if (messageOnly && !(resolved instanceof MessageType)) { addError("expected a message but was %s", name); return ProtoType.BYTES; // Just return any placeholder. } return resolved.type(); }
Field field = linker.dereference(context, option.name()); if (field == null) { linker.addError("unable to resolve option %s on %s", option.name(), context.type()); } else { ProtoMember protoMember = ProtoMember.get(context.type(), field); Field field = linker.dereference(context, name); if (field == null) { linker.addError("unable to resolve option %s on %s", name, context.type()); } else { ProtoMember protoMember = ProtoMember.get(context.type(), field);
void validateImport(Location location, ProtoType type) { // Map key type is always scalar. No need to validate it. if (type.isMap()) type = type.valueType(); if (type.isScalar()) return; String path = location.path(); String requiredImport = get(type).location().path(); if (!path.equals(requiredImport) && !imports.containsEntry(path, requiredImport)) { addError("%s needs to import %s", path, requiredImport); } }
void validate(Linker linker) { if (!Util.isValidTag(start()) || !Util.isValidTag(end())) { linker.withContext(this).addError("tags are out of range: %s to %s", start(), end()); } } }
private void validateTagUniqueness(Linker linker) { Multimap<Integer, EnumConstant> tagToConstant = LinkedHashMultimap.create(); for (EnumConstant constant : constants) { tagToConstant.put(constant.tag(), constant); } for (Map.Entry<Integer, Collection<EnumConstant>> entry : tagToConstant.asMap().entrySet()) { if (entry.getValue().size() > 1) { StringBuilder error = new StringBuilder(); error.append(String.format("multiple enum constants share tag %s:", entry.getKey())); int index = 1; for (EnumConstant constant : entry.getValue()) { error.append(String.format("\n %s. %s (%s)", index++, constant.name(), constant.location())); } linker.addError("%s", error); } } }
private void validateTagUniqueness(Linker linker) { Multimap<Integer, EnumConstant> tagToConstant = LinkedHashMultimap.create(); for (EnumConstant constant : constants) { tagToConstant.put(constant.tag(), constant); } for (Map.Entry<Integer, Collection<EnumConstant>> entry : tagToConstant.asMap().entrySet()) { if (entry.getValue().size() > 1) { StringBuilder error = new StringBuilder(); error.append(String.format("multiple enum constants share tag %s:", entry.getKey())); int index = 1; for (EnumConstant constant : entry.getValue()) { error.append(String.format("\n %s. %s (%s)", index++, constant.name(), constant.location())); } linker.addError("%s", error); } } }
/** Combine values for the same key, resolving conflicts based on their type. */ @SuppressWarnings("unchecked") private Object union(Linker linker, Object a, Object b) { if (a instanceof List) { return union((List<?>) a, (List<?>) b); } else if (a instanceof Map) { return union(linker, (Map<ProtoMember, Object>) a, (Map<ProtoMember, Object>) b); } else { linker.addError("conflicting options: %s, %s", a, b); return a; // Just return any placeholder. } }
/** Combine values for the same key, resolving conflicts based on their type. */ @SuppressWarnings("unchecked") private Object union(Linker linker, Object a, Object b) { if (a instanceof List) { return union((List<?>) a, (List<?>) b); } else if (a instanceof Map) { return union(linker, (Map<ProtoMember, Object>) a, (Map<ProtoMember, Object>) b); } else { linker.addError("conflicting options: %s, %s", a, b); return a; // Just return any placeholder. } }
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 validate(Linker linker) { linker = linker.withContext(this); if (isPacked() && !isPackable(linker, type)) { linker.addError("packed=true not permitted on %s", type); } if (extension && isRequired()) { linker.addError("extension fields cannot be required", type); } linker.validateImport(location(), type); }
void validate(Linker linker) { linker = linker.withContext(this); if (isPacked() && !isPackable(linker, type)) { linker.addError("packed=true not permitted on %s", type); } if (extension && isRequired()) { linker.addError("extension fields cannot be required", type); } linker.validateImport(location(), type); }
void validateImport(Location location, ProtoType type) { // Map key type is always scalar. No need to validate it. if (type.isMap()) type = type.valueType(); if (type.isScalar()) return; String path = location.path(); String requiredImport = get(type).location().path(); if (!path.equals(requiredImport) && !imports.containsEntry(path, requiredImport)) { addError("%s needs to import %s", path, requiredImport); } }
void validateImport(Location location, ProtoType type) { // Map key type is always scalar. No need to validate it. if (type.isMap()) type = type.valueType(); if (type.isScalar()) return; String path = location.path(); String requiredImport = get(type).location().path(); if (!path.equals(requiredImport) && !imports.containsEntry(path, requiredImport)) { addError("%s needs to import %s", path, requiredImport); } }
void validate(Linker linker) { if (!Util.isValidTag(start()) || !Util.isValidTag(end())) { linker.withContext(this).addError("tags are out of range: %s to %s", start(), end()); } } }
void validate(Linker linker) { if (!Util.isValidTag(start()) || !Util.isValidTag(end())) { linker.withContext(this).addError("tags are out of range: %s to %s", start(), end()); } } }