Search in sources :

Example 1 with EnclosingType

use of com.squareup.wire.schema.EnclosingType in project wire by square.

the class JavaGenerator method generateEnclosingType.

private TypeSpec generateEnclosingType(EnclosingType type) {
    ClassName javaType = (ClassName) typeName(type.type());
    TypeSpec.Builder builder = TypeSpec.classBuilder(javaType.simpleName()).addModifiers(PUBLIC, FINAL);
    if (javaType.enclosingClassName() != null) {
        builder.addModifiers(STATIC);
    }
    String documentation = type.documentation();
    if (!documentation.isEmpty()) {
        documentation += "\n\n<p>";
    }
    documentation += "<b>NOTE:</b> This type only exists to maintain class structure" + " for its nested types and is not an actual message.\n";
    builder.addJavadoc(documentation);
    builder.addMethod(MethodSpec.constructorBuilder().addModifiers(PRIVATE).addStatement("throw new $T()", AssertionError.class).build());
    for (Type nestedType : type.nestedTypes()) {
        builder.addType(generateType(nestedType));
    }
    return builder.build();
}
Also used : Type(com.squareup.wire.schema.Type) ProtoType(com.squareup.wire.schema.ProtoType) MessageType(com.squareup.wire.schema.MessageType) EnclosingType(com.squareup.wire.schema.EnclosingType) EnumType(com.squareup.wire.schema.EnumType) ClassName(com.squareup.javapoet.ClassName) ByteString(okio.ByteString) TypeSpec(com.squareup.javapoet.TypeSpec)

Aggregations

ClassName (com.squareup.javapoet.ClassName)1 TypeSpec (com.squareup.javapoet.TypeSpec)1 EnclosingType (com.squareup.wire.schema.EnclosingType)1 EnumType (com.squareup.wire.schema.EnumType)1 MessageType (com.squareup.wire.schema.MessageType)1 ProtoType (com.squareup.wire.schema.ProtoType)1 Type (com.squareup.wire.schema.Type)1 ByteString (okio.ByteString)1