Search in sources :

Example 1 with ArithmeticOperationExpr

use of com.google.api.generator.engine.ast.ArithmeticOperationExpr in project gapic-generator-java by googleapis.

the class JavaWriterVisitorTest method writeArithmeticOperationExpr_concatStringWithMethod.

@Test
public void writeArithmeticOperationExpr_concatStringWithMethod() {
    ValueExpr lhsExpr = ValueExpr.withValue(StringObjectValue.withValue("someWord"));
    MethodInvocationExpr methodInvocationExpr = MethodInvocationExpr.builder().setMethodName("getMethod").build();
    MethodInvocationExpr rhsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(methodInvocationExpr).setMethodName("getString").setReturnType(TypeNode.STRING).build();
    ArithmeticOperationExpr arithmeticOperationExpr = ArithmeticOperationExpr.concatWithExprs(lhsExpr, rhsExpr);
    arithmeticOperationExpr.accept(writerVisitor);
    assertThat(writerVisitor.write()).isEqualTo("\"someWord\" + getMethod().getString()");
}
Also used : ValueExpr(com.google.api.generator.engine.ast.ValueExpr) ArithmeticOperationExpr(com.google.api.generator.engine.ast.ArithmeticOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) Test(org.junit.Test)

Example 2 with ArithmeticOperationExpr

use of com.google.api.generator.engine.ast.ArithmeticOperationExpr in project gapic-generator-java by googleapis.

the class ImportWriterVisitorTest method writeArithmeticOperationExprImports.

@Test
public void writeArithmeticOperationExprImports() {
    MethodInvocationExpr lhsExpr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))).setMethodName("getSomething").setReturnType(TypeNode.STRING).build();
    ValueExpr rhsExpr = ValueExpr.createNullExpr();
    ArithmeticOperationExpr arithmeticOperationExpr = ArithmeticOperationExpr.concatWithExprs(lhsExpr, rhsExpr);
    arithmeticOperationExpr.accept(writerVisitor);
    assertEquals("import com.google.api.generator.engine.ast.Expr;\n\n", writerVisitor.write());
}
Also used : ValueExpr(com.google.api.generator.engine.ast.ValueExpr) ArithmeticOperationExpr(com.google.api.generator.engine.ast.ArithmeticOperationExpr) 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) Test(org.junit.Test)

Example 3 with ArithmeticOperationExpr

use of com.google.api.generator.engine.ast.ArithmeticOperationExpr in project gapic-generator-java by googleapis.

the class JavaWriterVisitorTest method writeArithmeticOperationExpr_concatStringWithNumber.

@Test
public void writeArithmeticOperationExpr_concatStringWithNumber() {
    ValueExpr rhsExpr = ValueExpr.withValue(PrimitiveValue.builder().setType(TypeNode.INT).setValue("5").build());
    ValueExpr lhsExpr = ValueExpr.withValue(StringObjectValue.withValue("someWord"));
    ArithmeticOperationExpr arithmeticOperationExpr = ArithmeticOperationExpr.concatWithExprs(lhsExpr, rhsExpr);
    arithmeticOperationExpr.accept(writerVisitor);
    assertThat(writerVisitor.write()).isEqualTo("\"someWord\" + 5");
}
Also used : ValueExpr(com.google.api.generator.engine.ast.ValueExpr) ArithmeticOperationExpr(com.google.api.generator.engine.ast.ArithmeticOperationExpr) Test(org.junit.Test)

Aggregations

ArithmeticOperationExpr (com.google.api.generator.engine.ast.ArithmeticOperationExpr)3 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)3 Test (org.junit.Test)3 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)2 AnonymousClassExpr (com.google.api.generator.engine.ast.AnonymousClassExpr)1 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)1 EnumRefExpr (com.google.api.generator.engine.ast.EnumRefExpr)1 Expr (com.google.api.generator.engine.ast.Expr)1 InstanceofExpr (com.google.api.generator.engine.ast.InstanceofExpr)1 LambdaExpr (com.google.api.generator.engine.ast.LambdaExpr)1 LogicalOperationExpr (com.google.api.generator.engine.ast.LogicalOperationExpr)1 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)1 ReferenceConstructorExpr (com.google.api.generator.engine.ast.ReferenceConstructorExpr)1 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)1 ReturnExpr (com.google.api.generator.engine.ast.ReturnExpr)1 TernaryExpr (com.google.api.generator.engine.ast.TernaryExpr)1 ThrowExpr (com.google.api.generator.engine.ast.ThrowExpr)1 UnaryOperationExpr (com.google.api.generator.engine.ast.UnaryOperationExpr)1 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)1