use of com.google.api.generator.engine.ast.ThisObjectValue in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeThisObjectValue_accessFieldAndInvokeMethod.
@Test
public void writeThisObjectValue_accessFieldAndInvokeMethod() {
VaporReference ref = VaporReference.builder().setName("Student").setPakkage("com.google.example.v1").build();
TypeNode classType = TypeNode.withReference(ref);
ThisObjectValue thisObjectValue = ThisObjectValue.withType(classType);
ValueExpr thisValueExpr = ValueExpr.withValue(thisObjectValue);
VariableExpr varExpr = VariableExpr.builder().setVariable(Variable.builder().setName("id").setType(TypeNode.STRING).build()).build();
Variable subVariable = Variable.builder().setName("name").setType(TypeNode.STRING).build();
VariableExpr thisVariableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(thisValueExpr).build();
MethodInvocationExpr methodExpr = MethodInvocationExpr.builder().setMethodName("getName").setExprReferenceExpr(ValueExpr.withValue(thisObjectValue)).setArguments(Arrays.asList(varExpr)).setReturnType(TypeNode.STRING).build();
AssignmentExpr assignmentExpr = AssignmentExpr.builder().setVariableExpr(thisVariableExpr).setValueExpr(methodExpr).build();
assignmentExpr.accept(writerVisitor);
assertThat(writerVisitor.write()).isEqualTo("this.name = this.getName(id)");
}
Aggregations