private void walk(Service service) { for (Processor<ServiceMethod> serviceMethodProcessor : serviceMethodProcessors) { for (ServiceMethod serviceMethod : service.getMethods()) { serviceMethodProcessor.run(context, serviceMethod); } } }
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 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); }
type.setProto(proto); String fullyQualifiedName = proto.getNamespace() + type.getName(); type.setFullyQualifiedName(fullyQualifiedName); context.register(fullyQualifiedName, type);
private List<JsonTreeNode> processProto(Proto proto) { List<JsonTreeNode> result = new ArrayList<>(); proto.getServices() .forEach(service -> result.add(ImmutableJsonTreeNode.builder() .label(service.getName()) .data(ImmutableNodeData.builder() .type(NodeType.SERVICE) .ref(service.getCanonicalName()) .build()) .build())); result.addAll(processContainer(proto)); return result; }
public static String getClassName(Service service) { String name = service.getName(); return Formatter.toPascalCase(name); }
@Override public void exitServiceBlock(ProtoParser.ServiceBlockContext ctx) { Service service = context.pop(Service.class); Proto proto = context.peek(Proto.class); String name = ctx.serviceName().getText(); service.setName(name); service.setSourceCodeLocation(getSourceCodeLocation(ctx)); proto.addService(service); attachComments(ctx, service, false); }
@Override public void enterServiceBlock(ProtoParser.ServiceBlockContext ctx) { Proto parent = context.peek(Proto.class); Service service = new Service(parent); context.push(service); }
@Override public void exitRpcMethod(ProtoParser.RpcMethodContext ctx) { final ServiceMethod method = context.pop(ServiceMethod.class); final Service service = context.peek(Service.class); String name = ctx.rpcName().getText(); String arg = ctx.rpcType(0).typeReference().getText(); boolean argStream = ctx.rpcType(0).STREAM() != null; String ret = ctx.rpcType(1).typeReference().getText(); boolean retStream = ctx.rpcType(1).STREAM() != null; method.setName(name); method.setArgTypeName(arg); method.setArgStream(argStream); method.setReturnTypeName(ret); method.setReturnStream(retStream); method.setSourceCodeLocation(getSourceCodeLocation(ctx)); service.addMethod(method); attachComments(ctx, method, true); } }
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); }
type.setProto(proto); String fullyQualifiedName = proto.getNamespace() + type.getName(); type.setFullyQualifiedName(fullyQualifiedName); context.register(fullyQualifiedName, type);
private List<JsonTreeNode> processProto(Proto proto) { List<JsonTreeNode> result = new ArrayList<>(); proto.getServices() .forEach(service -> result.add(ImmutableJsonTreeNode.builder() .label(service.getName()) .data(ImmutableNodeData.builder() .type(NodeType.SERVICE) .ref(service.getCanonicalName()) .build()) .build())); result.addAll(processContainer(proto)); return result; }
public static String getClassName(Service service) { String name = service.getName(); return Formatter.toPascalCase(name); }
@Override public void exitServiceBlock(ProtoParser.ServiceBlockContext ctx) { Service service = context.pop(Service.class); Proto proto = context.peek(Proto.class); String name = ctx.serviceName().getText(); service.setName(name); service.setSourceCodeLocation(getSourceCodeLocation(ctx)); proto.addService(service); attachComments(ctx, service, false); }
@Override public void enterServiceBlock(ProtoParser.ServiceBlockContext ctx) { Proto parent = context.peek(Proto.class); Service service = new Service(parent); context.push(service); }
@Override public void exitRpcMethod(ProtoParser.RpcMethodContext ctx) { final ServiceMethod method = context.pop(ServiceMethod.class); final Service service = context.peek(Service.class); String name = ctx.rpcName().getText(); String arg = ctx.rpcType(0).typeReference().getText(); boolean argStream = ctx.rpcType(0).STREAM() != null; String ret = ctx.rpcType(1).typeReference().getText(); boolean retStream = ctx.rpcType(1).STREAM() != null; method.setName(name); method.setArgTypeName(arg); method.setArgStream(argStream); method.setReturnTypeName(ret); method.setReturnStream(retStream); method.setSourceCodeLocation(getSourceCodeLocation(ctx)); service.addMethod(method); attachComments(ctx, method, true); } }
private void walk(Service service) { for (Processor<ServiceMethod> serviceMethodProcessor : serviceMethodProcessors) { for (ServiceMethod serviceMethod : service.getMethods()) { serviceMethodProcessor.run(context, serviceMethod); } } }
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, "}"); }
/** * 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; }
/** * 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; }