public static Builder builder(Location location) { return new AutoValue_MessageElement.Builder() .location(location) .documentation("") .fields(ImmutableList.<FieldElement>of()) .oneOfs(ImmutableList.<OneOfElement>of()) .nestedTypes(ImmutableList.<TypeElement>of()) .extensions(ImmutableList.<ExtensionsElement>of()) .options(ImmutableList.<OptionElement>of()) .reserveds(ImmutableList.<ReservedElement>of()) .groups(ImmutableList.<GroupElement>of()); }
MessageElement.Builder builder = MessageElement.builder(location) .name(name) .documentation(documentation);
@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); }
MessageElement.Builder builder = MessageElement.builder(location) .name(name) .documentation(documentation);
MessageElement.Builder builder = MessageElement.builder(location) .name(name) .documentation(documentation);
MessageElement toElement() { return MessageElement.builder(location) .documentation(documentation) .name(name) .options(options.toElements()) .fields(Field.toElements(declaredFields)) .nestedTypes(Type.toElements(nestedTypes)) .oneOfs(OneOf.toElements(oneOfs)) .extensions(Extensions.toElements(extensionsList)) .reserveds(Reserved.toElements(reserveds)) .build(); } }
public static Builder builder(Location location) { return new AutoValue_MessageElement.Builder() .location(location) .documentation("") .fields(ImmutableList.<FieldElement>of()) .oneOfs(ImmutableList.<OneOfElement>of()) .nestedTypes(ImmutableList.<TypeElement>of()) .extensions(ImmutableList.<ExtensionsElement>of()) .options(ImmutableList.<OptionElement>of()) .reserveds(ImmutableList.<ReservedElement>of()) .groups(ImmutableList.<GroupElement>of()); }
public static Builder builder(Location location) { return new AutoValue_MessageElement.Builder() .location(location) .documentation("") .fields(ImmutableList.<FieldElement>of()) .oneOfs(ImmutableList.<OneOfElement>of()) .nestedTypes(ImmutableList.<TypeElement>of()) .extensions(ImmutableList.<ExtensionsElement>of()) .options(ImmutableList.<OptionElement>of()) .reserveds(ImmutableList.<ReservedElement>of()) .groups(ImmutableList.<GroupElement>of()); }
MessageElement toElement() { return MessageElement.builder(location) .documentation(documentation) .name(name) .options(options.toElements()) .fields(Field.toElements(declaredFields)) .nestedTypes(Type.toElements(nestedTypes)) .oneOfs(OneOf.toElements(oneOfs)) .extensions(Extensions.toElements(extensionsList)) .reserveds(Reserved.toElements(reserveds)) .build(); } }
@Test public void roundTripToElement() { TypeElement element1 = MessageElement.builder(location.at(11, 1)) .name("Message1") .documentation("Some comments about Message1") .build(); TypeElement element2 = MessageElement.builder(location.at(12, 1))
@Test public void simpleWithDocumentationToSchema() { TypeElement element = MessageElement.builder(location) .name("Message") .documentation("Hello") .fields(ImmutableList.of( FieldElement.builder(location) .label(REQUIRED) .type("string") .name("name") .tag(1) .build())) .build(); String expected = "" + "// Hello\n" + "message Message {\n" + " required string name = 1;\n" + "}\n"; assertThat(element.toSchema()).isEqualTo(expected); }
MessageElement toElement() { return MessageElement.builder(location) .documentation(documentation) .name(name) .options(options.toElements()) .fields(Field.toElements(declaredFields)) .nestedTypes(Type.toElements(nestedTypes)) .oneOfs(OneOf.toElements(oneOfs)) .extensions(Extensions.toElements(extensionsList)) .reserveds(Reserved.toElements(reserveds)) .build(); } }