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 addMultipleOptions() { TypeElement element = MessageElement.builder(location).name("Message").build(); OptionElement kitKat = OptionElement.create("kit", Kind.STRING, "kat"); OptionElement fooBar = OptionElement.create("foo", Kind.STRING, "bar"); ProtoFileElement file = ProtoFileElement.builder(location) .options(ImmutableList.of(kitKat, fooBar)) .types(ImmutableList.of(element)) .build(); assertThat(file.options()).hasSize(2); }
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()); }
.services(ImmutableList.of(service1, service2)) .extendDeclarations(ImmutableList.of(extend1, extend2)) .options(ImmutableList.of(option1, option2)) .build(); ProtoFile file = ProtoFile.get(fileElement);
.services(ImmutableList.of(service1, service2)) .extendDeclarations(ImmutableList.of(extend1, extend2)) .options(ImmutableList.of(option1, option2)) .build(); String expected = ""
@Test public void packageDeclaration() throws Exception { String proto = "" + "package google.protobuf;\n" + "option java_package = \"com.google.protobuf\";\n" + "\n" + "// The protocol compiler can output a FileDescriptorSet containing the .proto\n" + "// files it parses.\n" + "message FileDescriptorSet {\n" + "}\n"; ProtoFileElement expected = ProtoFileElement.builder(location) .packageName("google.protobuf") .types(ImmutableList.<TypeElement>of( MessageElement.builder(location.at(6, 1)) .name("FileDescriptorSet") .documentation("The protocol compiler can output a FileDescriptorSet containing " + "the .proto\nfiles it parses.") .build())) .options(ImmutableList.of( OptionElement.create("java_package", Kind.STRING, "com.google.protobuf"))) .build(); assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected); }
@Test public void simpleWithOptionsToSchema() { TypeElement element = MessageElement.builder(location).name("Message").build(); OptionElement option = OptionElement.create("kit", Kind.STRING, "kat"); ProtoFileElement file = ProtoFileElement.builder(location) .options(ImmutableList.of(option)) .types(ImmutableList.of(element)) .build(); String expected = "" + "// file.proto\n" + "\n" + "option kit = \"kat\";\n" + "\n" + "message Message {}\n"; assertThat(file.toSchema()).isEqualTo(expected); }
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(); }