use of com.google.api.generator.engine.ast.MethodInvocationExpr 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.MethodInvocationExpr in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeRelationalOperationExpr_lessThan.
@Test
public void writeRelationalOperationExpr_lessThan() {
VariableExpr lhsExpr = VariableExpr.withVariable(createVariable("i", TypeNode.INT));
MethodInvocationExpr rhsExpr = MethodInvocationExpr.builder().setMethodName("getMaxNumber").setReturnType(TypeNode.INT).build();
RelationalOperationExpr lessThanWithExprs = RelationalOperationExpr.lessThanWithExprs(lhsExpr, rhsExpr);
lessThanWithExprs.accept(writerVisitor);
assertThat(writerVisitor.write()).isEqualTo("i < getMaxNumber()");
}
use of com.google.api.generator.engine.ast.MethodInvocationExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeLogicalOperationExprImports.
@Test
public void writeLogicalOperationExprImports() {
MethodInvocationExpr lhsExpr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(UnaryOperationExpr.class))).setMethodName("isValid").setReturnType(TypeNode.BOOLEAN).build();
VariableExpr rhsExpr = VariableExpr.builder().setVariable(createVariable("isGood", TypeNode.BOOLEAN)).build();
LogicalOperationExpr logicalOperationExpr = LogicalOperationExpr.logicalAndWithExprs(lhsExpr, rhsExpr);
logicalOperationExpr.accept(writerVisitor);
assertEquals("import com.google.api.generator.engine.ast.UnaryOperationExpr;\n\n", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.MethodInvocationExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeTernaryExprImports.
@Test
public void writeTernaryExprImports() {
MethodInvocationExpr conditionExpr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))).setMethodName("isExpr").setReturnType(TypeNode.BOOLEAN).build();
MethodInvocationExpr thenExpr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(Strings.class))).setMethodName("isNullOrEmpty").setReturnType(TypeNode.BOOLEAN).build();
MethodInvocationExpr elseExpr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(TypeNode.class))).setMethodName("isPrimitiveType").setReturnType(TypeNode.BOOLEAN).build();
TernaryExpr ternaryExpr = TernaryExpr.builder().setConditionExpr(conditionExpr).setThenExpr(thenExpr).setElseExpr(elseExpr).build();
ternaryExpr.accept(writerVisitor);
assertEquals(LineFormatter.lines("import com.google.api.generator.engine.ast.Expr;\n", "import com.google.api.generator.engine.ast.TypeNode;\n", "import com.google.common.base.Strings;\n\n"), writerVisitor.write());
}
use of com.google.api.generator.engine.ast.MethodInvocationExpr 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");
}
Aggregations