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 imports() throws Exception { String proto = "import \"src/test/resources/unittest_import.proto\";\n"; ProtoFileElement expected = ProtoFileElement.builder(location) .imports(ImmutableList.of( "src/test/resources/unittest_import.proto")) .build(); assertThat(ProtoParser.parse(location, proto)).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()); }
ProtoFileElement fileElement = ProtoFileElement.builder(location) .packageName("example.simple") .imports(ImmutableList.of("example.thing")) .publicImports(ImmutableList.of("example.other")) .types(ImmutableList.of(element1, element2))
ProtoFileElement file = ProtoFileElement.builder(location) .packageName("example.simple") .imports(ImmutableList.of("example.thing")) .publicImports(ImmutableList.of("example.other")) .types(ImmutableList.of(element1, element2))
@Test public void simpleWithBothImportsToSchema() { TypeElement element = MessageElement.builder(location).name("Message").build(); ProtoFileElement file = ProtoFileElement.builder(location) .imports(ImmutableList.of("example.thing")) .publicImports(ImmutableList.of("example.other")) .types(ImmutableList.of(element)) .build(); String expected = "" + "// file.proto\n" + "\n" + "import \"example.thing\";\n" + "import public \"example.other\";\n" + "\n" + "message Message {}\n"; assertThat(file.toSchema()).isEqualTo(expected); }
@Test public void simpleWithImportsToSchema() { TypeElement element = MessageElement.builder(location).name("Message").build(); ProtoFileElement file = ProtoFileElement.builder(location) .imports(ImmutableList.of("example.other")) .types(ImmutableList.of(element)) .build(); String expected = "" + "// file.proto\n" + "\n" + "import \"example.other\";\n" + "\n" + "message Message {}\n"; assertThat(file.toSchema()).isEqualTo(expected); }
@Test public void addMultipleDependencies() { TypeElement element = MessageElement.builder(location).name("Message").build(); ProtoFileElement file = ProtoFileElement.builder(location) .imports(ImmutableList.of("example.other", "example.another")) .types(ImmutableList.of(element)) .build(); assertThat(file.imports()).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(); }