private boolean hasEmptySelector(ProtoElement element) { // In case of proto files without package name, the generated selector will be empty, // we do not want to normalize such rules. return Strings.isNullOrEmpty(element.getFullName()); } }
private boolean hasEmptySelector(ProtoElement element) { // In case of proto files without package name, the generated selector will be empty, // we do not want to normalize such rules. return Strings.isNullOrEmpty(element.getFullName()); } }
@VisitsBefore public void accept(ProtoElement element) { protoElemFullNames.add(element.getFullName()); } }.accept(model);
/** * Returns the full name of this element, including package and outer messages for nested * elements. For a file, this will return the package name of the file. */ @Override public String getFullName() { // Don't need to care about root case as that overrides. if (Strings.isNullOrEmpty(parent.getFullName())) { return getSimpleName(); } return parent.getFullName() + "." + getSimpleName(); }
/** * Returns the full name of this element, including package and outer messages for nested * elements. For a file, this will return the package name of the file. */ @Override public String getFullName() { // Don't need to care about root case as that overrides. if (Strings.isNullOrEmpty(parent.getFullName())) { return getSimpleName(); } return parent.getFullName() + "." + getSimpleName(); }
@VisitsBefore public void accept(ProtoElement element) { protoElemFullNames.add(element.getFullName()); } }.accept(model);
@Override public String getParentFullName() { return protoField.getParent().getFullName(); }
@Override public String getParentFullName() { return protoInterface.getParent().getFullName(); }
@Override public TypeName getTypeName(ProtoElement elem) { return typeNameConverter.getTypeName(elem.getFullName()); }
private static String getShortName(ProtoElement elem) { return elem.getFullName().substring(elem.getFile().getFullName().length() + 1); }
private void markAsReachable(ProtoElement elem) { reachable.add(elem); ProtoElement parent = elem.getParent(); while (parent != null) { if (reachable.add(parent)) { // Parent was not reachable, check whether it is inScope and produce an error if not. if (!inScope(parent)) { errorSince( 2, parent, "Parent '%s' of visible element '%s' cannot be hidden. %s.", parent.getFullName(), elem.getFullName(), reasonForUnreachable(parent)); } } parent = parent.getParent(); } } }
private void markAsReachable(ProtoElement elem) { reachable.add(elem); ProtoElement parent = elem.getParent(); while (parent != null) { if (reachable.add(parent)) { // Parent was not reachable, check whether it is inScope and produce an error if not. if (!inScope(parent)) { errorSince( 2, parent, "Parent '%s' of visible element '%s' cannot be hidden. %s.", parent.getFullName(), elem.getFullName(), reasonForUnreachable(parent)); } } parent = parent.getParent(); } } }
private void mustBeInScope(ProtoElement context, ProtoElement elem) { visitInScope(elem); if (!isReachable(elem)) { // Check whether this is map field. In that case, suppress the error because we report // it for the entire map. if (context instanceof Field) { Field field = (Field) context; if (((MessageType) field.getParent()).isMapEntry()) { return; } } error( elem, "'%s' is hidden but required by visible '%s'. %s.", elem.getFullName(), context.getFullName(), reasonForUnreachable(elem)); } }
private void mustBeInScope(ProtoElement context, ProtoElement elem) { visitInScope(elem); if (!isReachable(elem)) { // Check whether this is map field. In that case, suppress the error because we report // it for the entire map. if (context instanceof Field) { Field field = (Field) context; if (((MessageType) field.getParent()).isMapEntry()) { return; } } error( elem, "'%s' is hidden but required by visible '%s'. %s.", elem.getFullName(), context.getFullName(), reasonForUnreachable(elem)); } }
@Override public void normalize(ProtoElement element, Service.Builder builder) { if (!isApplicable(element) || hasEmptySelector(element)) { return; } AttributeType attribute = element.getAttribute(key); if (attribute != null) { addToRuleBuilder(builder, element.getFullName(), attribute); } }
@Override public TypeName getTypeName(ProtoElement elem) { return typeNameConverter.getTypeName( NamePath.dotted(elem.getFullName()).withUpperPieces().toDoubleColoned()); }
@Override public void normalize(ProtoElement element, Service.Builder builder) { if (!isApplicable(element) || hasEmptySelector(element)) { return; } AttributeType attribute = element.getAttribute(key); if (attribute != null) { addToRuleBuilder(builder, element.getFullName(), attribute); } }
@Override @Nullable protected DocumentationRule fromIdlLayer(ProtoElement element) { // For the case there is no documentation rule, synthesize one from the comment // in the proto. String description = element.getFile().getDocumentation(element); if (inlineAllMessages && (element instanceof MessageType || element instanceof EnumType)) { description = description + "\n(== inline_message ==)"; } if (Strings.isNullOrEmpty(description)) { return null; } return DocumentationRule.newBuilder() .setSelector(element.getFullName()) .setDescription(trimCommentIndentation(description)) .build(); }
@Override @Nullable protected DocumentationRule fromIdlLayer(ProtoElement element) { // For the case there is no documentation rule, synthesize one from the comment // in the proto. String description = element.getFile().getDocumentation(element); if (inlineAllMessages && (element instanceof MessageType || element instanceof EnumType)) { description = description + "\n(== inline_message ==)"; } if (Strings.isNullOrEmpty(description)) { return null; } return DocumentationRule.newBuilder() .setSelector(element.getFullName()) .setDescription(trimCommentIndentation(description)) .build(); }
@Override public TypeName getTypeName(ProtoElement elem) { // Handle special wrapper types first String wrapper = WRAPPER_TYPE_MAP.getOrDefault(elem.getFullName(), null); if (wrapper != null) { return typeNameConverter.getTypeName(wrapper); } // Handle nested types, construct the required type prefix ProtoElement parentEl = elem.getParent(); String shortNamePrefix = ""; while (parentEl != null && parentEl instanceof MessageType) { shortNamePrefix = parentEl.getSimpleName() + "+Types+" + shortNamePrefix; parentEl = parentEl.getParent(); } String prefix = ""; if (parentEl instanceof ProtoFile) { ProtoFile protoFile = (ProtoFile) parentEl; String namespace = protoFile.getProto().getOptions().getCsharpNamespace(); if (Strings.isNullOrEmpty(namespace)) { for (String name : Splitter.on('.').split(parentEl.getFullName())) { prefix += Name.from(name).toUpperCamelAndDigits() + "."; } } else { prefix = namespace + "."; } } String shortName = shortNamePrefix + elem.getSimpleName(); return typeNameConverter.getTypeName(prefix + shortName); }