use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeBlockStatement_simple.
@Test
public void writeBlockStatement_simple() {
TypeNode someType = TypeNode.withReference(VaporReference.builder().setName("SomeClass").setPakkage("com.google.api.some.pakkage").build());
MethodInvocationExpr methodExpr = MethodInvocationExpr.builder().setMethodName("foobar").setStaticReferenceType(someType).build();
BlockStatement blockStatement = BlockStatement.builder().setBody(Arrays.asList(ExprStatement.withExpr(methodExpr))).build();
blockStatement.accept(writerVisitor);
assertEquals("{\nSomeClass.foobar();\n}\n", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.TypeNode 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());
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeInstanceofExprImports_basic.
@Test
public void writeInstanceofExprImports_basic() {
TypeNode exprType = TypeNode.withReference(ConcreteReference.withClazz(Expr.class));
TypeNode assignExprType = TypeNode.withReference(ConcreteReference.withClazz(AssignmentExpr.class));
Variable variable = Variable.builder().setName("x").setType(assignExprType).build();
VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).build();
InstanceofExpr expr = InstanceofExpr.builder().setExpr(variableExpr).setCheckType(exprType).build();
expr.accept(writerVisitor);
assertEquals(LineFormatter.lines("import com.google.api.generator.engine.ast.AssignmentExpr;\n", "import com.google.api.generator.engine.ast.Expr;\n\n"), writerVisitor.write());
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeReferenceConstructorExprImports_withArgs.
@Test
public void writeReferenceConstructorExprImports_withArgs() {
VaporReference ref = VaporReference.builder().setName("Student").setPakkage("com.google.example.v1").build();
TypeNode classType = TypeNode.withReference(ref);
VariableExpr streamVarExpr = VariableExpr.builder().setVariable(createVariable("stream", TypeNode.withReference(ConcreteReference.withClazz(LongStream.class)))).build();
ReferenceConstructorExpr referenceConstructorExpr = ReferenceConstructorExpr.thisBuilder().setArguments(Arrays.asList(streamVarExpr)).setType(classType).build();
referenceConstructorExpr.accept(writerVisitor);
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeVariableExprImports_wildcardType.
@Test
public void writeVariableExprImports_wildcardType() {
TypeNode wildcardListType = TypeNode.withReference(ConcreteReference.builder().setClazz(List.class).setGenerics(Arrays.asList(TypeNode.WILDCARD_REFERENCE)).build());
// Constructs `List<?> x`.
Variable variable = Variable.builder().setName("x").setType(wildcardListType).build();
VariableExpr variableExpr = VariableExpr.builder().setIsDecl(true).setVariable(variable).build();
variableExpr.accept(writerVisitor);
assertEquals("import java.util.List;\n\n", writerVisitor.write());
}
Aggregations