public static Builder builder(Location location) { return new AutoValue_ServiceElement.Builder() .location(location) .documentation("") .rpcs(ImmutableList.<RpcElement>of()) .options(ImmutableList.<OptionElement>of()); }
static ImmutableList<ServiceElement> toElements(ImmutableList<Service> services) { ImmutableList.Builder<ServiceElement> elements = new ImmutableList.Builder<>(); for (Service service : services) { elements.add(ServiceElement.builder(service.location) .documentation(service.documentation) .name(service.name) .rpcs(Rpc.toElements(service.rpcs)) .options(service.options.toElements()) .build()); } return elements.build(); } }
/** Reads a service declaration and returns it. */ private ServiceElement readService(Location location, String documentation) { String name = reader.readName(); ServiceElement.Builder builder = ServiceElement.builder(location) .name(name) .documentation(documentation); reader.require('{'); ImmutableList.Builder<RpcElement> rpcs = ImmutableList.builder(); ImmutableList.Builder<OptionElement> options = ImmutableList.builder(); while (true) { String rpcDocumentation = reader.readDocumentation(); if (reader.peekChar('}')) break; Object declared = readDeclaration(rpcDocumentation, Context.SERVICE); if (declared instanceof RpcElement) { rpcs.add((RpcElement) declared); } else if (declared instanceof OptionElement) { options.add((OptionElement) declared); } } return builder.options(options.build()) .rpcs(rpcs.build()) .build(); }
/** Reads a service declaration and returns it. */ private ServiceElement readService(Location location, String documentation) { String name = readName(); ServiceElement.Builder builder = ServiceElement.builder(location) .name(name) .documentation(documentation); if (readChar() != '{') throw unexpected("expected '{'"); ImmutableList.Builder<RpcElement> rpcs = ImmutableList.builder(); ImmutableList.Builder<OptionElement> options = ImmutableList.builder(); while (true) { String rpcDocumentation = readDocumentation(); if (peekChar() == '}') { pos++; break; } Object declared = readDeclaration(rpcDocumentation, Context.SERVICE); if (declared instanceof RpcElement) { rpcs.add((RpcElement) declared); } else if (declared instanceof OptionElement) { options.add((OptionElement) declared); } } return builder.options(options.build()) .rpcs(rpcs.build()) .build(); }
/** Reads a service declaration and returns it. */ private ServiceElement readService(Location location, String documentation) { String name = reader.readName(); ServiceElement.Builder builder = ServiceElement.builder(location) .name(name) .documentation(documentation); reader.require('{'); ImmutableList.Builder<RpcElement> rpcs = ImmutableList.builder(); ImmutableList.Builder<OptionElement> options = ImmutableList.builder(); while (true) { String rpcDocumentation = reader.readDocumentation(); if (reader.peekChar('}')) break; Object declared = readDeclaration(rpcDocumentation, Context.SERVICE); if (declared instanceof RpcElement) { rpcs.add((RpcElement) declared); } else if (declared instanceof OptionElement) { options.add((OptionElement) declared); } } return builder.options(options.build()) .rpcs(rpcs.build()) .build(); }
static ImmutableList<ServiceElement> toElements(ImmutableList<Service> services) { ImmutableList.Builder<ServiceElement> elements = new ImmutableList.Builder<>(); for (Service service : services) { elements.add(ServiceElement.builder(service.location) .documentation(service.documentation) .name(service.name) .rpcs(Rpc.toElements(service.rpcs)) .options(service.options.toElements()) .build()); } return elements.build(); } }
static ImmutableList<ServiceElement> toElements(ImmutableList<Service> services) { ImmutableList.Builder<ServiceElement> elements = new ImmutableList.Builder<>(); for (Service service : services) { elements.add(ServiceElement.builder(service.location) .documentation(service.documentation) .name(service.name) .rpcs(Rpc.toElements(service.rpcs)) .options(service.options.toElements()) .build()); } return elements.build(); } }
public static Builder builder(Location location) { return new AutoValue_ServiceElement.Builder() .location(location) .documentation("") .rpcs(ImmutableList.<RpcElement>of()) .options(ImmutableList.<OptionElement>of()); }
public static Builder builder(Location location) { return new AutoValue_ServiceElement.Builder() .location(location) .documentation("") .rpcs(ImmutableList.<RpcElement>of()) .options(ImmutableList.<OptionElement>of()); }
ServiceElement service1 = ServiceElement.builder(location.at(19, 1)) .name("Service1") .rpcs(ImmutableList.<RpcElement>of(RpcElement.builder(location.at(20, 3)) .name("MethodA") .requestType("Message2")
.options(ImmutableList.of( OptionElement.create("default_timeout", Kind.NUMBER, "30", true))) .rpcs(ImmutableList.of( RpcElement.builder(location.at(4, 3)) .name("Search")
ServiceElement.builder(location.at(1, 1)) .name("RouteGuide") .rpcs(ImmutableList.of( RpcElement.builder(location.at(2, 3)) .name("GetFeature")
@Test public void singleWithOptionsToSchema() { ServiceElement service = ServiceElement.builder(location) .name("Service") .options(ImmutableList.of( OptionElement.create("foo", Kind.STRING, "bar"))) .rpcs(ImmutableList.of( RpcElement.builder(location) .name("Name") .requestType("RequestType") .responseType("ResponseType") .build())) .build(); String expected = "" + "service Service {\n" + " option foo = \"bar\";\n" + "\n" + " rpc Name (RequestType) returns (ResponseType);\n" + "}\n"; assertThat(service.toSchema()).isEqualTo(expected); }
@Test public void singleWithDocumentationToSchema() { ServiceElement service = ServiceElement.builder(location) .name("Service") .documentation("Hello") .rpcs(ImmutableList.of( RpcElement.builder(location) .name("Name") .requestType("RequestType") .responseType("ResponseType") .build())) .build(); String expected = "" + "// Hello\n" + "service Service {\n" + " rpc Name (RequestType) returns (ResponseType);\n" + "}\n"; assertThat(service.toSchema()).isEqualTo(expected); }
@Test public void multipleToSchema() { RpcElement rpc = RpcElement.builder(location) .name("Name") .requestType("RequestType") .responseType("ResponseType") .build(); ServiceElement service = ServiceElement.builder(location) .name("Service") .rpcs(ImmutableList.of(rpc, rpc)) .build(); String expected = "" + "service Service {\n" + " rpc Name (RequestType) returns (ResponseType);\n" + " rpc Name (RequestType) returns (ResponseType);\n" + "}\n"; assertThat(service.toSchema()).isEqualTo(expected); }
@Test public void addMultipleRpcs() { RpcElement firstName = RpcElement.builder(location) .name("FirstName") .requestType("RequestType") .responseType("ResponseType") .build(); RpcElement lastName = RpcElement.builder(location) .name("LastName") .requestType("RequestType") .responseType("ResponseType") .build(); ServiceElement service = ServiceElement.builder(location) .name("Service") .rpcs(ImmutableList.of(firstName, lastName)) .build(); assertThat(service.rpcs()).hasSize(2); }
@Test public void singleToSchema() { ServiceElement service = ServiceElement.builder(location) .name("Service") .rpcs(ImmutableList.of( RpcElement.builder(location) .name("Name") .requestType("RequestType") .responseType("ResponseType") .build())) .build(); String expected = "" + "service Service {\n" + " rpc Name (RequestType) returns (ResponseType);\n" + "}\n"; assertThat(service.toSchema()).isEqualTo(expected); }
@Test public void addMultipleOptions() { OptionElement kitKat = OptionElement.create("kit", Kind.STRING, "kat"); OptionElement fooBar = OptionElement.create("foo", Kind.STRING, "bar"); ServiceElement service = ServiceElement.builder(location) .name("Service") .options(ImmutableList.of(kitKat, fooBar)) .rpcs(ImmutableList.of( RpcElement.builder(location) .name("Name") .requestType("RequestType") .responseType("ResponseType") .build())) .build(); assertThat(service.options()).hasSize(2); }