private void serviceToString(Service service, StringBuilder sb) { appendLine(sb, "service %s {", service.getName()); for (ServiceMethod serviceMethod : service.getMethods()) { commentsToString(serviceMethod.getCommentLines(), sb, 2); appendLine(sb, " rpc %s (%s) returns (%s);\n", serviceMethod.getName(), serviceMethod.getArgTypeName(), serviceMethod.getReturnTypeName()); } if (!service.getMethods().isEmpty()) { sb.setLength(sb.length() - 1); } appendLine(sb, "}"); }
private void walk(Service service) { for (Processor<ServiceMethod> serviceMethodProcessor : serviceMethodProcessors) { for (ServiceMethod serviceMethod : service.getMethods()) { serviceMethodProcessor.run(context, serviceMethod); } } }
/** * Get a service method by it's name. */ public ServiceMethod getMethod(String name) { for (ServiceMethod serviceMethod : getMethods()) { if (serviceMethod.getName().equals(name)) { return serviceMethod; } } return null; }
private void walk(Service service) { for (Processor<ServiceMethod> serviceMethodProcessor : serviceMethodProcessors) { for (ServiceMethod serviceMethod : service.getMethods()) { serviceMethodProcessor.run(context, serviceMethod); } } }
/** * Get a service method by it's name. */ public ServiceMethod getMethod(String name) { for (ServiceMethod serviceMethod : getMethods()) { if (serviceMethod.getName().equals(name)) { return serviceMethod; } } return null; }
private void processService(Service service) { List<ServiceMethod> methods = service.getMethods(); checkDuplicateServiceMethodNames(methods); }
private void processService(Service service) { List<ServiceMethod> methods = service.getMethods(); checkDuplicateServiceMethodNames(methods); }
private void serviceToString(Service service, StringBuilder sb) { appendLine(sb, "service %s {", service.getName()); for (ServiceMethod serviceMethod : service.getMethods()) { if (!serviceMethod.getCommentLines().isEmpty()) { appendLine(sb, " //" + serviceMethod.getComments()); } appendLine(sb, " rpc %s (%s) returns (%s);\n", serviceMethod.getName(), serviceMethod.getArgTypeName(), serviceMethod.getReturnTypeName()); } if (!service.getMethods().isEmpty()) { sb.setLength(sb.length() - 1); } appendLine(sb, "}"); }
private void process(Module module, Service service) { ImmutableServiceDescriptor descriptor = ImmutableServiceDescriptor.builder() .type(NodeType.SERVICE) .name(service.getName()) .canonicalName(service.getCanonicalName()) .description(markdownProcessor.toHtml(service.getComments())) .options(service.getOptions().toMap()) .addAllMethods(service.getMethods().stream() .map(method -> ImmutableServiceMethod.builder() .name(method.getName()) .argTypeId(method.getArgType().getCanonicalName()) .argStream(method.isArgStream()) .returnTypeId(method.getReturnType().getCanonicalName()) .returnStream(method.isReturnStream()) .description(markdownProcessor.toHtml(method.getComments())) .options(method.getOptions().toMap()) .build()) .collect(Collectors.toList())) .build(); String output = "data/type/" + service.getCanonicalName() + ".json"; write(module, output, descriptor); }
/** * Build usage index for given collection of proto files. */ public static UsageIndex build(Collection<Proto> protos) { UsageIndex usageIndex = new UsageIndex(); for (Proto proto : protos) { ProtoWalker.newInstance(proto.getContext()) .onMessage(message -> { for (Field field : message.getFields()) { usageIndex.register(field.getType(), message); } }) .onService(service -> { for (ServiceMethod serviceMethod : service.getMethods()) { usageIndex.register(serviceMethod.getArgType(), service); usageIndex.register(serviceMethod.getReturnType(), service); } }) .walk(); } return usageIndex; }
private void process(Module module, Service service) { ImmutableServiceDescriptor descriptor = ImmutableServiceDescriptor.builder() .type(NodeType.SERVICE) .name(service.getName()) .canonicalName(service.getCanonicalName()) .description(markdownProcessor.toHtml(service.getComments())) .options(service.getOptions().toMap()) .addAllMethods(service.getMethods().stream() .map(method -> ImmutableServiceMethod.builder() .name(method.getName()) .argTypeId(method.getArgType().getCanonicalName()) .argStream(method.isArgStream()) .returnTypeId(method.getReturnType().getCanonicalName()) .returnStream(method.isReturnStream()) .description(markdownProcessor.toHtml(method.getComments())) .options(method.getOptions().toMap()) .build()) .collect(Collectors.toList())) .build(); String output = "data/type/" + service.getCanonicalName() + ".json"; write(module, output, descriptor); }
/** * Build usage index for given collection of proto files. */ public static UsageIndex build(Collection<Proto> protos) { UsageIndex usageIndex = new UsageIndex(); for (Proto proto : protos) { ProtoWalker.newInstance(proto.getContext()) .onMessage(message -> { for (Field field : message.getFields()) { usageIndex.register(field.getType(), message); } }) .onService(service -> { for (ServiceMethod serviceMethod : service.getMethods()) { usageIndex.register(serviceMethod.getArgType(), service); usageIndex.register(serviceMethod.getReturnType(), service); } }) .walk(); } return usageIndex; }
private void resolveTypeReferences(ProtoContext context) { Proto proto = context.getProto(); Deque<String> scopeLookupList = createScopeLookupList(proto); for (Service service : proto.getServices()) { for (ServiceMethod method : service.getMethods()) { String argTypeName = method.getArgTypeName(); FieldType argType = resolveFieldType(method, context, scopeLookupList, argTypeName); if (!(argType instanceof Message)) { String format = "Cannot use '%s' as a service method argument type: not a message"; throw new ParserException(method, format, argType.getName()); } method.setArgType((Message) argType); String returnTypeName = method.getReturnTypeName(); FieldType returnType = resolveFieldType(method, context, scopeLookupList, returnTypeName); if (!(returnType instanceof Message)) { String format = "Cannot use '%s' as a service method return type: not a message"; throw new ParserException(method, format, returnType.getName()); } method.setReturnType((Message) returnType); } } resolveTypeReferences(context, scopeLookupList, proto); }
private void resolveTypeReferences(ProtoContext context) { Proto proto = context.getProto(); Deque<String> scopeLookupList = createScopeLookupList(proto); for (Service service : proto.getServices()) { for (ServiceMethod method : service.getMethods()) { String argTypeName = method.getArgTypeName(); FieldType argType = resolveFieldType(method, context, scopeLookupList, argTypeName); if (!(argType instanceof Message)) { String format = "Cannot use '%s' as a service method argument type: not a message"; throw new ParserException(method, format, argType.getName()); } method.setArgType((Message) argType); String returnTypeName = method.getReturnTypeName(); FieldType returnType = resolveFieldType(method, context, scopeLookupList, returnTypeName); if (!(returnType instanceof Message)) { String format = "Cannot use '%s' as a service method return type: not a message"; throw new ParserException(method, format, returnType.getName()); } method.setReturnType((Message) returnType); } } resolveTypeReferences(context, scopeLookupList, proto); }