Search in sources :

Example 41 with MethodInvocationExpr

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());
}
Also used : MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) BlockStatement(com.google.api.generator.engine.ast.BlockStatement) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 42 with MethodInvocationExpr

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()");
}
Also used : RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Test(org.junit.Test)

Example 43 with MethodInvocationExpr

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());
}
Also used : MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) UnaryOperationExpr(com.google.api.generator.engine.ast.UnaryOperationExpr) Test(org.junit.Test)

Example 44 with MethodInvocationExpr

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());
}
Also used : ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) UnaryOperationExpr(com.google.api.generator.engine.ast.UnaryOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) InstanceofExpr(com.google.api.generator.engine.ast.InstanceofExpr) ArithmeticOperationExpr(com.google.api.generator.engine.ast.ArithmeticOperationExpr) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Strings(com.google.common.base.Strings) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) Test(org.junit.Test)

Example 45 with MethodInvocationExpr

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");
}
Also used : ValueExpr(com.google.api.generator.engine.ast.ValueExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Aggregations

MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)103 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)76 TypeNode (com.google.api.generator.engine.ast.TypeNode)72 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)59 Expr (com.google.api.generator.engine.ast.Expr)50 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)48 ArrayList (java.util.ArrayList)41 Variable (com.google.api.generator.engine.ast.Variable)39 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)38 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)36 Statement (com.google.api.generator.engine.ast.Statement)33 List (java.util.List)31 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)29 Test (org.junit.Test)29 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)27 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)26 Arrays (java.util.Arrays)26 JavaStyle (com.google.api.generator.gapic.utils.JavaStyle)25 Map (java.util.Map)25 Function (java.util.function.Function)24