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());
}
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)");
}
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());
}
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());
}
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()");
}
Aggregations