Search in sources :

Example 1 with SuperObjectValue

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

the class JavaWriterVisitorTest method writeSuperObjectValue_accessFieldAndInvokeMethod.

@Test
public void writeSuperObjectValue_accessFieldAndInvokeMethod() {
    VaporReference ref = VaporReference.builder().setName("Student").setPakkage("com.google.example.v1").build();
    TypeNode classType = TypeNode.withReference(ref);
    SuperObjectValue superObjectValue = SuperObjectValue.withType(classType);
    ValueExpr superValueExpr = ValueExpr.withValue(superObjectValue);
    Variable subVariable = Variable.builder().setName("name").setType(TypeNode.STRING).build();
    VariableExpr superVariableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(superValueExpr).build();
    MethodInvocationExpr methodExpr = MethodInvocationExpr.builder().setMethodName("getName").setExprReferenceExpr(ValueExpr.withValue(superObjectValue)).setReturnType(TypeNode.STRING).build();
    AssignmentExpr assignmentExpr = AssignmentExpr.builder().setVariableExpr(superVariableExpr).setValueExpr(methodExpr).build();
    assignmentExpr.accept(writerVisitor);
    assertThat(writerVisitor.write()).isEqualTo("super.name = super.getName()");
}
Also used : ValueExpr(com.google.api.generator.engine.ast.ValueExpr) Variable(com.google.api.generator.engine.ast.Variable) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) SuperObjectValue(com.google.api.generator.engine.ast.SuperObjectValue) Test(org.junit.Test)

Example 2 with SuperObjectValue

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

the class ImportWriterVisitorTest method writeSuperObjectValueImports.

@Test
public void writeSuperObjectValueImports() {
    VaporReference ref = VaporReference.builder().setName("Student").setPakkage("com.google.example.examples.v1").build();
    TypeNode typeNode = TypeNode.withReference(ref);
    SuperObjectValue superObjectValue = SuperObjectValue.withType(typeNode);
    MethodInvocationExpr methodExpr = MethodInvocationExpr.builder().setMethodName("getName").setExprReferenceExpr(ValueExpr.withValue(superObjectValue)).setReturnType(TypeNode.STRING).build();
    methodExpr.accept(writerVisitor);
    assertEquals("import com.google.example.examples.v1.Student;\n\n", writerVisitor.write());
}
Also used : MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) TypeNode(com.google.api.generator.engine.ast.TypeNode) SuperObjectValue(com.google.api.generator.engine.ast.SuperObjectValue) Test(org.junit.Test)

Aggregations

MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)2 SuperObjectValue (com.google.api.generator.engine.ast.SuperObjectValue)2 TypeNode (com.google.api.generator.engine.ast.TypeNode)2 VaporReference (com.google.api.generator.engine.ast.VaporReference)2 Test (org.junit.Test)2 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)1 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)1 Variable (com.google.api.generator.engine.ast.Variable)1 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)1