use of com.squareup.wire.schema.ProtoType in project wire by square.
the class JavaGenerator method fieldType.
private TypeName fieldType(Field field) {
ProtoType type = field.type();
if (type.isMap()) {
return ParameterizedTypeName.get(ClassName.get(Map.class), typeName(type.keyType()), typeName(type.valueType()));
}
TypeName messageType = typeName(type);
return field.isRepeated() ? listOf(messageType) : messageType;
}
use of com.squareup.wire.schema.ProtoType in project wire by square.
the class ProfileLoaderTest method profileInZip.
@Test
public void profileInZip() throws IOException {
FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
Files.createDirectories(fileSystem.getPath("/source"));
Path zip = fileSystem.getPath("/source/protos.zip");
ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(zip));
writeFile(zipOutputStream, "a/b/message.proto", "" + "package a.b;\n" + "message Message {" + "}");
writeFile(zipOutputStream, "a/b/android.wire", "" + "syntax = \"wire2\";\n" + "package a.b;\n" + "import \"a/b/message.proto\";\n" + "type a.b.Message {\n" + " target java.lang.Object using com.example.Message#ADAPTER;\n" + "}");
zipOutputStream.close();
Schema schema = new SchemaLoader().addSource(zip).load();
Profile profile = new ProfileLoader(fileSystem, "android").schema(schema).load();
ProtoType message = ProtoType.get("a.b.Message");
assertThat(profile.getTarget(message)).isEqualTo(ClassName.OBJECT);
assertThat(profile.getAdapter(message)).isEqualTo(new AdapterConstant("com.example.Message#ADAPTER"));
}
Aggregations