Search in sources :

Example 6 with ProtoType

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;
}
Also used : ProtoType(com.squareup.wire.schema.ProtoType) TypeName(com.squareup.javapoet.TypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with ProtoType

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"));
}
Also used : Path(java.nio.file.Path) ProtoType(com.squareup.wire.schema.ProtoType) SchemaLoader(com.squareup.wire.schema.SchemaLoader) ZipOutputStream(java.util.zip.ZipOutputStream) FileSystem(java.nio.file.FileSystem) Schema(com.squareup.wire.schema.Schema) Test(org.junit.Test)

Aggregations

ProtoType (com.squareup.wire.schema.ProtoType)7 ClassName (com.squareup.javapoet.ClassName)3 TypeName (com.squareup.javapoet.TypeName)2 Type (com.squareup.wire.schema.Type)2 LinkedHashMap (java.util.LinkedHashMap)2 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 MethodSpec (com.squareup.javapoet.MethodSpec)1 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)1 TypeSpec (com.squareup.javapoet.TypeSpec)1 ProfileFileElement (com.squareup.wire.java.internal.ProfileFileElement)1 TypeConfigElement (com.squareup.wire.java.internal.TypeConfigElement)1 EnclosingType (com.squareup.wire.schema.EnclosingType)1 EnumType (com.squareup.wire.schema.EnumType)1 MessageType (com.squareup.wire.schema.MessageType)1 ProtoFile (com.squareup.wire.schema.ProtoFile)1 RepoBuilder (com.squareup.wire.schema.RepoBuilder)1 Rpc (com.squareup.wire.schema.Rpc)1 Schema (com.squareup.wire.schema.Schema)1 SchemaException (com.squareup.wire.schema.SchemaException)1