use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeThrowExpr_messageExpr.
@Test
public void writeThrowExpr_messageExpr() {
TypeNode npeType = TypeNode.withExceptionClazz(NullPointerException.class);
Expr messageExpr = MethodInvocationExpr.builder().setMethodName("foobar").setReturnType(TypeNode.STRING).build();
ThrowExpr throwExpr = ThrowExpr.builder().setType(npeType).setMessageExpr(messageExpr).build();
throwExpr.accept(writerVisitor);
assertEquals("throw new NullPointerException(foobar())", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writePrimitiveType.
@Test
public void writePrimitiveType() {
TypeNode intType = TypeNode.INT;
assertThat(intType).isNotNull();
intType.accept(writerVisitor);
assertEquals("int", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeMethodInvocationExpr_staticRef.
@Test
public void writeMethodInvocationExpr_staticRef() {
TypeNode someType = TypeNode.withReference(VaporReference.builder().setName("SomeClass").setPakkage("com.google.api.some.pakkage").build());
MethodInvocationExpr methodExpr = MethodInvocationExpr.builder().setMethodName("foobar").setStaticReferenceType(someType).build();
methodExpr.accept(writerVisitor);
assertEquals("SomeClass.foobar()", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeMethodDefinition_constructor.
@Test
public void writeMethodDefinition_constructor() {
TypeNode returnType = TypeNode.withReference(VaporReference.builder().setName("LibrarySettings").setPakkage("com.google.example.library.v1").build());
MethodDefinition methodDefinition = MethodDefinition.constructorBuilder().setScope(ScopeNode.PUBLIC).setReturnType(returnType).build();
methodDefinition.accept(writerVisitor);
assertEquals("public LibrarySettings() {\n}\n\n", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeNewObjectExpr_basic.
@Test
public void writeNewObjectExpr_basic() {
// isGeneric() is true, but generics() is empty.
ConcreteReference ref = ConcreteReference.withClazz(List.class);
TypeNode type = TypeNode.withReference(ref);
NewObjectExpr newObjectExpr = NewObjectExpr.builder().setIsGeneric(true).setType(type).build();
newObjectExpr.accept(writerVisitor);
assertEquals("new List<>()", writerVisitor.write());
}
Aggregations