if (packageName != null) throw reader.unexpected(location, "too many package names"); packageName = reader.readName(); fileBuilder.packageName(packageName); prefix = packageName + "."; reader.require(';');
@Test public void emptyWithPackageToSchema() { ProtoFileElement file = ProtoFileElement.builder(location) .packageName("example.simple") .build(); String expected = "" + "// file.proto\n" + "package example.simple;\n"; assertThat(file.toSchema()).isEqualTo(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); }
if (packageName != null) throw unexpected(location, "too many package names"); packageName = readName(); fileBuilder.packageName(packageName); prefix = packageName + "."; if (readChar() != ';') throw unexpected("expected ';'");
if (packageName != null) throw reader.unexpected(location, "too many package names"); packageName = reader.readName(); fileBuilder.packageName(packageName); prefix = packageName + "."; reader.require(';');
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(); }
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(); }
.build(); ProtoFileElement fileElement = ProtoFileElement.builder(location) .packageName("example.simple") .imports(ImmutableList.of("example.thing")) .publicImports(ImmutableList.of("example.other"))
.build(); ProtoFileElement file = ProtoFileElement.builder(location) .packageName("example.simple") .imports(ImmutableList.of("example.thing")) .publicImports(ImmutableList.of("example.other"))
@Test public void extendInMessageWithPackage() throws Exception { String proto = "" + "package kit.kat;\n" + "\n" + "message Bar {\n" + " extend Foo {\n" + " optional Bar bar = 126;\n" + " }\n" + "}"; ProtoFileElement expected = ProtoFileElement.builder(location) .packageName("kit.kat") .types(ImmutableList.<TypeElement>of( MessageElement.builder(location.at(3, 1)) .name("Bar") .build())) .extendDeclarations(ImmutableList.of( ExtendElement.builder(location.at(4, 3)) .name("Foo") .fields(ImmutableList.of( FieldElement.builder(location.at(5, 5)) .label(OPTIONAL) .type("Bar") .name("bar") .tag(126) .build())) .build())) .build(); assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected); }
@Test public void fqcnExtendInMessageWithPackage() throws Exception { String proto = "" + "package kit.kat;\n" + "\n" + "message Bar {\n" + " extend example.Foo {\n" + " optional Bar bar = 126;\n" + " }\n" + "}"; ProtoFileElement expected = ProtoFileElement.builder(location) .packageName("kit.kat") .types(ImmutableList.<TypeElement>of(MessageElement.builder(location.at(3, 1)) .name("Bar") .build())) .extendDeclarations(ImmutableList.of( ExtendElement.builder(location.at(4, 3)) .name("example.Foo") .fields(ImmutableList.of( FieldElement.builder(location.at(5, 5)) .label(OPTIONAL) .type("Bar") .name("bar") .tag(126) .build())) .build())) .build(); assertThat(ProtoParser.parse(location, proto)).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(); }