Search in sources :

Example 96 with VariableExpr

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

the class JavaWriterVisitorTest method writeLambdaExpr_body.

@Test
public void writeLambdaExpr_body() {
    VariableExpr argVarExpr = VariableExpr.builder().setVariable(Variable.builder().setName("arg").setType(TypeNode.INT).build()).build();
    VariableExpr fooVarExpr = VariableExpr.builder().setVariable(Variable.builder().setName("foo").setType(TypeNode.INT).build()).build();
    ExprStatement statement = ExprStatement.withExpr(AssignmentExpr.builder().setVariableExpr(fooVarExpr.toBuilder().setIsDecl(true).build()).setValueExpr(ValueExpr.builder().setValue(PrimitiveValue.builder().setType(TypeNode.INT).setValue("1").build()).build()).build());
    LambdaExpr lambdaExpr = LambdaExpr.builder().setArguments(argVarExpr.toBuilder().setIsDecl(true).build()).setReturnExpr(ValueExpr.withValue(StringObjectValue.withValue("foo"))).setBody(Arrays.asList(statement)).build();
    lambdaExpr.accept(writerVisitor);
    assertEquals("arg -> {\nint foo = 1;\nreturn \"foo\";\n}", writerVisitor.write());
}
Also used : LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Test(org.junit.Test)

Example 97 with VariableExpr

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

the class JavaWriterVisitorTest method writeAssignmentOperationExpr_xorAssignment.

@Test
public void writeAssignmentOperationExpr_xorAssignment() {
    VariableExpr lhsExpr = createVariableExpr("h", TypeNode.INT);
    TypeNode objectType = TypeNode.withReference(VaporReference.builder().setName("Objects").setPakkage("java.lang.Object").build());
    MethodInvocationExpr rhsExpr = MethodInvocationExpr.builder().setReturnType(TypeNode.INT).setMethodName("hashCode").setStaticReferenceType(objectType).setArguments(Arrays.asList(VariableExpr.withVariable(createVariable("fixedValue", TypeNode.OBJECT)))).build();
    AssignmentOperationExpr assignmentOperationExpr = AssignmentOperationExpr.xorAssignmentWithExprs(lhsExpr, rhsExpr);
    assignmentOperationExpr.accept(writerVisitor);
    assertThat(writerVisitor.write()).isEqualTo("h ^= Objects.hashCode(fixedValue)");
}
Also used : MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) AssignmentOperationExpr(com.google.api.generator.engine.ast.AssignmentOperationExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 98 with VariableExpr

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

the class JavaWriterVisitorTest method writeAssignmentExpr_nullObjectValueReferenceType.

@Test
public void writeAssignmentExpr_nullObjectValueReferenceType() {
    Variable variable = Variable.builder().setName("x").setType(TypeNode.STRING).build();
    VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).setIsDecl(true).build();
    Value value = NullObjectValue.create();
    Expr valueExpr = ValueExpr.builder().setValue(value).build();
    AssignmentExpr assignExpr = AssignmentExpr.builder().setVariableExpr(variableExpr).setValueExpr(valueExpr).build();
    assignExpr.accept(writerVisitor);
    assertEquals("String x = null", writerVisitor.write());
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) 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) CastExpr(com.google.api.generator.engine.ast.CastExpr) ArithmeticOperationExpr(com.google.api.generator.engine.ast.ArithmeticOperationExpr) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) AssignmentOperationExpr(com.google.api.generator.engine.ast.AssignmentOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) NullObjectValue(com.google.api.generator.engine.ast.NullObjectValue) Value(com.google.api.generator.engine.ast.Value) SuperObjectValue(com.google.api.generator.engine.ast.SuperObjectValue) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) Test(org.junit.Test)

Example 99 with VariableExpr

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

the class JavaWriterVisitorTest method writeVariableExpr_basic.

@Test
public void writeVariableExpr_basic() {
    Variable variable = Variable.builder().setName("x").setType(TypeNode.INT).build();
    VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).build();
    variableExpr.accept(writerVisitor);
    assertEquals("x", writerVisitor.write());
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Test(org.junit.Test)

Example 100 with VariableExpr

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

the class JavaWriterVisitorTest method writeRelationalOperationExpr_equalTo.

@Test
public void writeRelationalOperationExpr_equalTo() {
    VariableExpr variableExprLHS = VariableExpr.withVariable(Variable.builder().setType(TypeNode.BOOLEAN_OBJECT).setName("isGood").build());
    MethodInvocationExpr methodInvocationExpr = MethodInvocationExpr.builder().setMethodName("isBad").setReturnType(TypeNode.BOOLEAN).build();
    RelationalOperationExpr equalToOperationExpr = RelationalOperationExpr.equalToWithExprs(variableExprLHS, methodInvocationExpr);
    equalToOperationExpr.accept(writerVisitor);
    assertThat(writerVisitor.write()).isEqualTo("isGood == isBad()");
}
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)

Aggregations

VariableExpr (com.google.api.generator.engine.ast.VariableExpr)217 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)137 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)132 TypeNode (com.google.api.generator.engine.ast.TypeNode)118 Expr (com.google.api.generator.engine.ast.Expr)114 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)107 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)91 Variable (com.google.api.generator.engine.ast.Variable)88 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)87 ArrayList (java.util.ArrayList)87 Test (org.junit.Test)82 Statement (com.google.api.generator.engine.ast.Statement)80 List (java.util.List)64 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)62 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)58 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)56 CastExpr (com.google.api.generator.engine.ast.CastExpr)53 CommentStatement (com.google.api.generator.engine.ast.CommentStatement)53 Arrays (java.util.Arrays)48 IfStatement (com.google.api.generator.engine.ast.IfStatement)47