use of com.squareup.wire.schema.RepoBuilder in project wire by square.
the class JavaGeneratorTest method map.
@Test
public void map() throws Exception {
Schema schema = new RepoBuilder().add("message.proto", "" + "message Message {\n" + " map<string, CdnResource> templates = 1;\n" + " message CdnResource {\n" + " }\n" + "}\n").schema();
MessageType message = (MessageType) schema.getType("Message");
JavaGenerator javaGenerator = JavaGenerator.get(schema);
TypeSpec typeSpec = javaGenerator.generateType(message);
assertThat(JavaFile.builder("", typeSpec).build().toString()).contains("" + " @WireField(\n" + " tag = 1,\n" + " keyAdapter = \"com.squareup.wire.ProtoAdapter#STRING\",\n" + " adapter = \"Message$CdnResource#ADAPTER\"\n" + " )\n" + " public final Map<String, CdnResource> templates;\n");
}
use of com.squareup.wire.schema.RepoBuilder in project wire by square.
the class JavaGeneratorTest method generateAbstractAdapterWithRedactedField.
@Test
public void generateAbstractAdapterWithRedactedField() throws IOException {
RepoBuilder repoBuilder = new RepoBuilder().add("message.proto", "" + "import \"option_redacted.proto\";\n" + "message ProtoMessage {\n" + " optional string secret = 1 [(squareup.protos.redacted_option.redacted) = true];\n" + "}\n").add("option_redacted.proto").add("android.wire", "" + "syntax = \"wire2\";\n" + "import \"message.proto\";\n" + "type ProtoMessage {\n" + " target JavaMessage using JavaMessage#ADAPTER;\n" + "}\n");
assertThat(repoBuilder.generateCode("ProtoMessage", "android")).contains("" + " @Override\n" + " public JavaMessage redact(JavaMessage value) {\n" + " return null;\n" + " }\n");
}
use of com.squareup.wire.schema.RepoBuilder in project wire by square.
the class ProfileLoaderTest method test.
@Test
public void test() throws IOException {
RepoBuilder repoBuilder = new RepoBuilder().add("a/b/message1.proto", "" + "package a.b;\n" + "message Message1 {\n" + "}\n").add("a/b/c/message2.proto", "" + "package a.b.c;\n" + "message Message2 {\n" + "}\n").add("android.wire", "" + "syntax = \"wire2\";\n" + "import \"a/b/message1.proto\";\n" + "type a.b.Message1 {\n" + " target java.lang.Object using com.example.Message1#OBJECT_ADAPTER;\n" + "}\n").add("a/b/c/android.wire", "" + "syntax = \"wire2\";\n" + "import \"a/b/c/message2.proto\";\n" + "package a.b.c;\n" + "type a.b.c.Message2 {\n" + " target java.lang.String using com.example.Message2#STRING_ADAPTER;\n" + "}\n");
Profile profile = repoBuilder.profile("android");
ProtoType message1 = ProtoType.get("a.b.Message1");
assertThat(profile.getTarget(message1)).isEqualTo(ClassName.OBJECT);
assertThat(profile.getAdapter(message1)).isEqualTo(new AdapterConstant("com.example.Message1#OBJECT_ADAPTER"));
ProtoType message2 = ProtoType.get("a.b.c.Message2");
assertThat(profile.getTarget(message2)).isEqualTo(ClassName.get(String.class));
assertThat(profile.getAdapter(message2)).isEqualTo(new AdapterConstant("com.example.Message2#STRING_ADAPTER"));
}
use of com.squareup.wire.schema.RepoBuilder in project wire by square.
the class JavaGeneratorTest method generateTypeUsesNameAllocatorInMessageBuilderBuild.
@Test
public void generateTypeUsesNameAllocatorInMessageBuilderBuild() throws Exception {
RepoBuilder repoBuilder = new RepoBuilder().add("message.proto", "" + "message Message {\n" + " required float long = 1;\n" + "}\n");
assertThat(repoBuilder.generateCode("Message")).contains("" + " @Override\n" + " public Message build() {\n" + " if (long_ == null) {\n" + " throw Internal.missingRequiredFields(long_, \"long\");\n" + " }\n" + " return new Message(long_, super.buildUnknownFields());\n" + " }\n");
}
use of com.squareup.wire.schema.RepoBuilder in project wire by square.
the class JavaGeneratorTest method nestedAbstractAdapterIsStatic.
@Test
public void nestedAbstractAdapterIsStatic() throws IOException {
RepoBuilder repoBuilder = new RepoBuilder().add("message.proto", "" + "message A {\n" + " message B {\n" + " optional string c = 1;\n" + " }\n" + "}\n").add("android.wire", "" + "syntax = \"wire2\";\n" + "import \"message.proto\";\n" + "type A.B {\n" + " target java.lang.String using AbAdapter#INSTANCE;\n" + "}\n");
assertThat(repoBuilder.generateCode("A", "android")).contains("" + " public abstract static class AbstractBAdapter extends ProtoAdapter<String> {\n");
}
Aggregations