private String getElemName(ProtoElement elem) { // Fast path if we have a top-level message if (elem.getParent() instanceof ProtoFile) { return elem.getSimpleName(); } // The number of components in the same with the layers of nesting. // Init the list to something a little more than sensible. List<String> nameComponents = new ArrayList<>(5); while (!(elem instanceof ProtoFile)) { nameComponents.add(elem.getSimpleName()); elem = elem.getParent(); } Collections.reverse(nameComponents); return Joiner.on("_").join(nameComponents); }
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(); } } }
ProtoElement parentElem = elem.getParent(); if (parentElem != null && parentElem instanceof ProtoFile) { ProtoFile protoFile = (ProtoFile) parentElem;
private static String getEnumTypeClassName(MethodContext context, TypeModel type) { checkArgument( type instanceof ProtoTypeRef, "%s: type %s is not a proto type", context.getMethodModel().getSimpleName(), type); checkArgument( ((ProtoTypeRef) type).isEnum(), "%s: type %s is not an enum type", context.getMethodModel().getSimpleName(), type); TypeRef protoType = ((ProtoTypeRef) type).getProtoType(); ProtoElement t = protoType.getEnumType(); List<String> names = new ArrayList<>(); while (!(t instanceof ProtoFile)) { names.add(t.getSimpleName()); t = t.getParent(); } names.add("enums"); StringBuilder builder = new StringBuilder(); for (String name : Lists.reverse(names)) { builder.append(name).append("."); } return builder.substring(0, builder.length() - 1); } }
private static boolean inEndpoint(Model model, ProtoElement element) { String endpoint = model.getAttribute(ENDPOINT_FILTER_KEY); if (element instanceof ProtoFile) { return true; } else if (element instanceof Interface) { Endpoint endpointConfig = getEndpointConfig(model, endpoint); if (endpointConfig != null) { return true; } return false; } else { return inEndpoint(model, element.getParent()); } }
private static boolean inEndpoint(Model model, ProtoElement element) { String endpoint = model.getAttribute(ENDPOINT_FILTER_KEY); if (element instanceof ProtoFile) { return true; } else if (element instanceof Interface) { Endpoint endpointConfig = getEndpointConfig(model, endpoint); if (endpointConfig != null) { return true; } return false; } else { return inEndpoint(model, element.getParent()); } }
current = ((ProtoElement) current).getParent(); } else { current = null;
current = ((ProtoElement) current).getParent(); } else { current = null;
ProtoElement parent = elem.getParent(); if (parent != null && parent instanceof MessageType) { MessageType parentMessage = (MessageType) parent;
@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); }