use of com.google.api.generator.engine.ast.ValueExpr in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeAssignmentOperationExpr_multiplyAssignment.
@Test
public void writeAssignmentOperationExpr_multiplyAssignment() {
VariableExpr lhsExpr = createVariableExpr("h", TypeNode.INT);
ValueExpr rhsExpr = ValueExpr.withValue(PrimitiveValue.builder().setType(TypeNode.INT).setValue("1000003").build());
AssignmentOperationExpr assignmentOperationExpr = AssignmentOperationExpr.multiplyAssignmentWithExprs(lhsExpr, rhsExpr);
assignmentOperationExpr.accept(writerVisitor);
assertThat(writerVisitor.write()).isEqualTo("h *= 1000003");
}
use of com.google.api.generator.engine.ast.ValueExpr 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()");
}
use of com.google.api.generator.engine.ast.ValueExpr in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeAssignmentExpr_varToVar.
@Test
public void writeAssignmentExpr_varToVar() {
Variable variable = Variable.builder().setName("foobar").setType(TypeNode.INT).build();
VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).setIsStatic(true).setIsFinal(true).setScope(ScopeNode.PRIVATE).setIsDecl(true).build();
Variable anotherVariable = Variable.builder().setName("y").setType(TypeNode.INT).build();
Expr valueExpr = VariableExpr.builder().setVariable(anotherVariable).build();
AssignmentExpr assignExpr = AssignmentExpr.builder().setVariableExpr(variableExpr).setValueExpr(valueExpr).build();
assignExpr.accept(writerVisitor);
assertEquals("private static final int foobar = y", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.ValueExpr in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeGeneralForStatement_basicIsNotDecl.
@Test
public void writeGeneralForStatement_basicIsNotDecl() {
AssignmentExpr assignExpr = createAssignmentExpr("x", "3", TypeNode.INT);
Statement assignExprStatement = ExprStatement.withExpr(assignExpr);
List<Statement> body = Arrays.asList(assignExprStatement, assignExprStatement);
VariableExpr localVarExpr = createVariableExpr("i", TypeNode.INT);
ValueExpr initValueExpr = ValueExpr.withValue(PrimitiveValue.builder().setValue("1").setType(TypeNode.INT).build());
ValueExpr maxValueExpr = ValueExpr.withValue(PrimitiveValue.builder().setValue("10").setType(TypeNode.INT).build());
GeneralForStatement forStatement = GeneralForStatement.incrementWith(localVarExpr, initValueExpr, maxValueExpr, body);
forStatement.accept(writerVisitor);
assertEquals(String.format("%s%s%s%s", "for (i = 1; i < 10; i++) {\n", "int x = 3;\n", "int x = 3;\n", "}\n"), writerVisitor.write());
}
use of com.google.api.generator.engine.ast.ValueExpr 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());
}
Aggregations