Search in sources :

Example 1 with EnumRefExpr

use of com.google.api.generator.engine.ast.EnumRefExpr in project gapic-generator-java by googleapis.

the class JavaWriterVisitorTest method writeEnumRefExpr_basic.

@Test
public void writeEnumRefExpr_basic() {
    TypeNode enumType = TypeNode.withReference(ConcreteReference.builder().setClazz(TypeNode.TypeKind.class).setIsStaticImport(true).build());
    EnumRefExpr enumRefExpr = EnumRefExpr.builder().setName("VOID").setType(enumType).build();
    enumRefExpr.accept(writerVisitor);
    assertEquals("TypeKind.VOID", writerVisitor.write());
}
Also used : EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 2 with EnumRefExpr

use of com.google.api.generator.engine.ast.EnumRefExpr in project gapic-generator-java by googleapis.

the class ImportWriterVisitorTest method writeEnumRefExprImports_basic.

@Test
public void writeEnumRefExprImports_basic() {
    TypeNode enumType = TypeNode.withReference(ConcreteReference.builder().setClazz(TypeNode.TypeKind.class).setIsStaticImport(true).build());
    EnumRefExpr enumRefExpr = EnumRefExpr.builder().setName("VOID").setType(enumType).build();
    enumRefExpr.accept(writerVisitor);
    assertEquals("import static com.google.api.generator.engine.ast.TypeNode.TypeKind;\n\n", writerVisitor.write());
}
Also used : EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 3 with EnumRefExpr

use of com.google.api.generator.engine.ast.EnumRefExpr in project gapic-generator-java by googleapis.

the class JavaWriterVisitorTest method writeEnumRefExpr_nested.

@Test
public void writeEnumRefExpr_nested() {
    TypeNode enumType = TypeNode.withReference(ConcreteReference.withClazz(TypeNode.TypeKind.class));
    EnumRefExpr enumRefExpr = EnumRefExpr.builder().setName("VOID").setType(enumType).build();
    enumRefExpr.accept(writerVisitor);
    assertEquals("TypeNode.TypeKind.VOID", writerVisitor.write());
}
Also used : EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 4 with EnumRefExpr

use of com.google.api.generator.engine.ast.EnumRefExpr in project gapic-generator-java by googleapis.

the class HttpJsonServiceStubClassComposer method getMethodTypeExpr.

private List<Expr> getMethodTypeExpr(Method protoMethod) {
    MethodType methodType;
    switch(protoMethod.stream()) {
        case NONE:
            methodType = MethodType.UNARY;
            break;
        case SERVER:
            methodType = MethodType.SERVER_STREAMING;
            break;
        case CLIENT:
        // Not feasible to suppor in REST
        case BIDI:
        // Not feasible to suppor in REST
        default:
            throw new UnsupportedOperationException(String.format("Methods of type %s are not supported by REST transport", protoMethod.stream()));
    }
    EnumRefExpr expr = EnumRefExpr.builder().setName(methodType.toString()).setType(TypeNode.withReference(ConcreteReference.builder().setClazz(ApiMethodDescriptor.MethodType.class).build())).build();
    return Collections.singletonList(expr);
}
Also used : MethodType(com.google.api.gax.httpjson.ApiMethodDescriptor.MethodType) ApiMethodDescriptor(com.google.api.gax.httpjson.ApiMethodDescriptor) EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr)

Example 5 with EnumRefExpr

use of com.google.api.generator.engine.ast.EnumRefExpr in project gapic-generator-java by googleapis.

the class ImportWriterVisitorTest method writeEnumRefExprImports_nested.

@Test
public void writeEnumRefExprImports_nested() {
    TypeNode enumType = TypeNode.withReference(ConcreteReference.withClazz(TypeNode.TypeKind.class));
    EnumRefExpr enumRefExpr = EnumRefExpr.builder().setName("VOID").setType(enumType).build();
    enumRefExpr.accept(writerVisitor);
    assertEquals("import com.google.api.generator.engine.ast.TypeNode;\n\n", writerVisitor.write());
}
Also used : EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Aggregations

EnumRefExpr (com.google.api.generator.engine.ast.EnumRefExpr)5 TypeNode (com.google.api.generator.engine.ast.TypeNode)4 Test (org.junit.Test)4 ApiMethodDescriptor (com.google.api.gax.httpjson.ApiMethodDescriptor)1 MethodType (com.google.api.gax.httpjson.ApiMethodDescriptor.MethodType)1