public static Builder builder(Location location) { return new AutoValue_ProtoFileElement.Builder() .location(location) .imports(ImmutableList.<String>of()) .publicImports(ImmutableList.<String>of()) .types(ImmutableList.<TypeElement>of()) .services(ImmutableList.<ServiceElement>of()) .extendDeclarations(ImmutableList.<ExtendElement>of()) .options(ImmutableList.<OptionElement>of()); }
ProtoFileElement readProtoFile() { while (true) { String documentation = reader.readDocumentation(); if (reader.exhausted()) { return fileBuilder.syntax(syntax) .publicImports(publicImports.build()) .imports(imports.build()) .types(nestedTypes.build()) .services(services.build()) .extendDeclarations(extendsList.build()) .options(options.build()) .build(); } Object declaration = readDeclaration(documentation, Context.FILE); if (declaration instanceof TypeElement) { nestedTypes.add((TypeElement) declaration); } else if (declaration instanceof ServiceElement) { services.add((ServiceElement) declaration); } else if (declaration instanceof OptionElement) { options.add((OptionElement) declaration); } else if (declaration instanceof ExtendElement) { extendsList.add((ExtendElement) declaration); } } }
@Test public void simpleWithServicesToSchema() { TypeElement element = MessageElement.builder(location).name("Message").build(); ServiceElement service = ServiceElement.builder(location).name("Service").build(); ProtoFileElement file = ProtoFileElement.builder(location) .types(ImmutableList.of(element)) .services(ImmutableList.of(service)) .build(); String expected = "" + "// file.proto\n" + "\n" + "message Message {}\n" + "\n" + "service Service {}\n"; assertThat(file.toSchema()).isEqualTo(expected); }
ProtoFileElement readProtoFile() { while (true) { String documentation = reader.readDocumentation(); if (reader.exhausted()) { return fileBuilder.syntax(syntax) .publicImports(publicImports.build()) .imports(imports.build()) .types(nestedTypes.build()) .services(services.build()) .extendDeclarations(extendsList.build()) .options(options.build()) .build(); } Object declaration = readDeclaration(documentation, Context.FILE); if (declaration instanceof TypeElement) { nestedTypes.add((TypeElement) declaration); } else if (declaration instanceof ServiceElement) { services.add((ServiceElement) declaration); } else if (declaration instanceof OptionElement) { options.add((OptionElement) declaration); } else if (declaration instanceof ExtendElement) { extendsList.add((ExtendElement) declaration); } } }
ProtoFileElement readProtoFile() { while (true) { String documentation = readDocumentation(); if (pos == data.length) { return fileBuilder.syntax(syntax) .publicImports(publicImports.build()) .imports(imports.build()) .types(nestedTypes.build()) .services(services.build()) .extendDeclarations(extendsList.build()) .options(options.build()) .build(); } Object declaration = readDeclaration(documentation, Context.FILE); if (declaration instanceof TypeElement) { nestedTypes.add((TypeElement) declaration); } else if (declaration instanceof ServiceElement) { services.add((ServiceElement) declaration); } else if (declaration instanceof OptionElement) { options.add((OptionElement) declaration); } else if (declaration instanceof ExtendElement) { extendsList.add((ExtendElement) declaration); } } }
ProtoFileElement toElement() { return ProtoFileElement.builder(location) .imports(imports) .publicImports(publicImports) .packageName(packageName) .types(Type.toElements(types)) .services(Service.toElements(services)) .extendDeclarations(Extend.toElements(extendList)) .options(options.toElements()) .syntax(syntax) .build(); }
public static Builder builder(Location location) { return new AutoValue_ProtoFileElement.Builder() .location(location) .imports(ImmutableList.<String>of()) .publicImports(ImmutableList.<String>of()) .types(ImmutableList.<TypeElement>of()) .services(ImmutableList.<ServiceElement>of()) .extendDeclarations(ImmutableList.<ExtendElement>of()) .options(ImmutableList.<OptionElement>of()); }
ProtoFileElement toElement() { return ProtoFileElement.builder(location) .imports(imports) .publicImports(publicImports) .packageName(packageName) .types(Type.toElements(types)) .services(Service.toElements(services)) .extendDeclarations(Extend.toElements(extendList)) .options(options.toElements()) .syntax(syntax) .build(); }
public static Builder builder(Location location) { return new AutoValue_ProtoFileElement.Builder() .location(location) .imports(ImmutableList.<String>of()) .publicImports(ImmutableList.<String>of()) .types(ImmutableList.<TypeElement>of()) .services(ImmutableList.<ServiceElement>of()) .extendDeclarations(ImmutableList.<ExtendElement>of()) .options(ImmutableList.<OptionElement>of()); }
.publicImports(ImmutableList.of("example.other")) .types(ImmutableList.of(element1, element2)) .services(ImmutableList.of(service1, service2)) .extendDeclarations(ImmutableList.of(extend1, extend2)) .options(ImmutableList.of(option1, option2))
.publicImports(ImmutableList.of("example.other")) .types(ImmutableList.of(element1, element2)) .services(ImmutableList.of(service1, service2)) .extendDeclarations(ImmutableList.of(extend1, extend2)) .options(ImmutableList.of(option1, option2))
+ "}"; ProtoFileElement expected = ProtoFileElement.builder(location) .services(ImmutableList.of( ServiceElement.builder(location.at(1, 1)) .name("RouteGuide")
+ "}"; ProtoFileElement expected = ProtoFileElement.builder(location) .services(ImmutableList.of( ServiceElement.builder(location.at(1, 1)) .name("SearchService")
@Test public void addMultipleServices() { ServiceElement service1 = ServiceElement.builder(location).name("Service1").build(); ServiceElement service2 = ServiceElement.builder(location).name("Service2").build(); ProtoFileElement file = ProtoFileElement.builder(location) .services(ImmutableList.of(service1, service2)) .build(); assertThat(file.services()).hasSize(2); }
ProtoFileElement toElement() { return ProtoFileElement.builder(location) .imports(imports) .publicImports(publicImports) .packageName(packageName) .types(Type.toElements(types)) .services(Service.toElements(services)) .extendDeclarations(Extend.toElements(extendList)) .options(options.toElements()) .syntax(syntax) .build(); }