use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeThrowExprImports_basic.
@Test
public void writeThrowExprImports_basic() {
TypeNode exceptionTypes = TypeNode.withReference(ConcreteReference.withClazz(IOException.class));
String message = "Some message asdf";
ThrowExpr throwExpr = ThrowExpr.builder().setType(exceptionTypes).setMessageExpr(message).build();
throwExpr.accept(writerVisitor);
assertEquals("import java.io.IOException;\n\n", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeRelationOperationExpr_notEqualTo.
@Test
public void writeRelationOperationExpr_notEqualTo() {
TypeNode someType = TypeNode.withReference(VaporReference.builder().setName("SomeClass").setPakkage("com.google.api.generator.engine").build());
MethodInvocationExpr lhsExpr = MethodInvocationExpr.builder().setMethodName("getName").setStaticReferenceType(someType).setReturnType(TypeNode.STRING).build();
ValueExpr rhsExpr = ValueExpr.createNullExpr();
RelationalOperationExpr notEqualToOperationExpr = RelationalOperationExpr.notEqualToWithExprs(lhsExpr, rhsExpr);
notEqualToOperationExpr.accept(writerVisitor);
assertThat(writerVisitor.write()).isEqualTo("SomeClass.getName() != null");
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeThrowExprImports_messageAndCauseExpr.
@Test
public void writeThrowExprImports_messageAndCauseExpr() {
TypeNode npeType = TypeNode.withExceptionClazz(NullPointerException.class);
Expr messageExpr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(IfStatement.class))).setMethodName("conditionExpr").setReturnType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))).build();
messageExpr = MethodInvocationExpr.builder().setExprReferenceExpr(messageExpr).setMethodName("foobar").setReturnType(TypeNode.STRING).build();
ThrowExpr throwExpr = ThrowExpr.builder().setType(npeType).setMessageExpr(messageExpr).setCauseExpr(NewObjectExpr.builder().setType(TypeNode.withExceptionClazz(FileNotFoundException.class)).build()).build();
throwExpr.accept(writerVisitor);
assertEquals(LineFormatter.lines("import com.google.api.generator.engine.ast.Expr;\n", "import com.google.api.generator.engine.ast.IfStatement;\n", "import java.io.FileNotFoundException;\n\n"), writerVisitor.write());
}
use of com.google.api.generator.engine.ast.TypeNode 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());
}
use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeSuperObjectValueImports.
@Test
public void writeSuperObjectValueImports() {
VaporReference ref = VaporReference.builder().setName("Student").setPakkage("com.google.example.examples.v1").build();
TypeNode typeNode = TypeNode.withReference(ref);
SuperObjectValue superObjectValue = SuperObjectValue.withType(typeNode);
MethodInvocationExpr methodExpr = MethodInvocationExpr.builder().setMethodName("getName").setExprReferenceExpr(ValueExpr.withValue(superObjectValue)).setReturnType(TypeNode.STRING).build();
methodExpr.accept(writerVisitor);
assertEquals("import com.google.example.examples.v1.Student;\n\n", writerVisitor.write());
}
Aggregations