Search in sources :

Example 6 with VaporReference

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

the class JavaWriterVisitorTest method writeLogicalOperationExpr_logicalAnd.

@Test
public void writeLogicalOperationExpr_logicalAnd() {
    VariableExpr lhsExpr = VariableExpr.withVariable(createVariable("isEmpty", TypeNode.BOOLEAN));
    VaporReference ref = VaporReference.builder().setName("Student").setPakkage("com.google.example.v1").build();
    TypeNode classType = TypeNode.withReference(ref);
    MethodInvocationExpr rhsExpr = MethodInvocationExpr.builder().setMethodName("isValid").setExprReferenceExpr(ValueExpr.withValue(ThisObjectValue.withType(classType))).setReturnType(TypeNode.BOOLEAN).build();
    LogicalOperationExpr logicalOperationExpr = LogicalOperationExpr.logicalAndWithExprs(lhsExpr, rhsExpr);
    logicalOperationExpr.accept(writerVisitor);
    assertThat(writerVisitor.write()).isEqualTo("isEmpty && this.isValid()");
}
Also used : MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 7 with VaporReference

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

the class JavaWriterVisitorTest method writeReferenceConstructorExpr_thisConstructorWithArguments.

@Test
public void writeReferenceConstructorExpr_thisConstructorWithArguments() {
    VaporReference ref = VaporReference.builder().setName("Student").setPakkage("com.google.example.v1").build();
    TypeNode classType = TypeNode.withReference(ref);
    VariableExpr idVarExpr = VariableExpr.builder().setVariable(Variable.builder().setName("id").setType(TypeNode.STRING).build()).build();
    VariableExpr nameVarExpr = VariableExpr.builder().setVariable(Variable.builder().setName("name").setType(TypeNode.STRING).build()).build();
    ReferenceConstructorExpr referenceConstructorExpr = ReferenceConstructorExpr.thisBuilder().setArguments(Arrays.asList(idVarExpr, nameVarExpr)).setType(classType).build();
    referenceConstructorExpr.accept(writerVisitor);
    assertThat(writerVisitor.write()).isEqualTo("this(id, name)");
}
Also used : VaporReference(com.google.api.generator.engine.ast.VaporReference) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) Test(org.junit.Test)

Example 8 with VaporReference

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

the class JavaWriterVisitorTest method writeReferenceConstructorExpr_superConstructorWithNoArguments.

@Test
public void writeReferenceConstructorExpr_superConstructorWithNoArguments() {
    VaporReference ref = VaporReference.builder().setName("Parent").setPakkage("com.google.example.v1").build();
    TypeNode classType = TypeNode.withReference(ref);
    ReferenceConstructorExpr referenceConstructorExpr = ReferenceConstructorExpr.superBuilder().setType(classType).build();
    referenceConstructorExpr.accept(writerVisitor);
    assertThat(writerVisitor.write()).isEqualTo("super()");
}
Also used : VaporReference(com.google.api.generator.engine.ast.VaporReference) TypeNode(com.google.api.generator.engine.ast.TypeNode) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) Test(org.junit.Test)

Example 9 with VaporReference

use of com.google.api.generator.engine.ast.VaporReference 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)");
}
Also used : ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) 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) Test(org.junit.Test)

Example 10 with VaporReference

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

the class JavaCodeGeneratorTest method createLibServiceCtor.

private MethodDefinition createLibServiceCtor() {
    VaporReference libraryServiceStubRef = createVaporReference("com.google.exmaple.library.core", "LibraryServiceStub");
    NewObjectExpr arrayList = createNewObjectExpr(ArrayList.class);
    NewObjectExpr hashMap = createNewObjectExpr(HashMap.class);
    ReferenceConstructorExpr superExpr = ReferenceConstructorExpr.superBuilder().setType(TypeNode.withReference(libraryServiceStubRef)).build();
    ValueExpr thisValueExpr = ValueExpr.withValue(ThisObjectValue.withType(TypeNode.withReference(libraryServiceStubRef)));
    VariableExpr thisVariableExpr = createVarExprFromRefVarExpr(shelfListVar, thisValueExpr);
    AssignmentExpr shelfListAssignmentExpr = createAssignmentExpr(thisVariableExpr, arrayList);
    AssignmentExpr shelfMapAssignmentExpr = createAssignmentExpr(VariableExpr.withVariable(shelfMapVar), hashMap);
    return MethodDefinition.constructorBuilder().setBody(Arrays.asList(ExprStatement.withExpr(superExpr), ExprStatement.withExpr(shelfListAssignmentExpr), ExprStatement.withExpr(shelfMapAssignmentExpr))).setReturnType(TypeNode.withReference(libraryServiceStubRef)).setScope(ScopeNode.PUBLIC).build();
}
Also used : ValueExpr(com.google.api.generator.engine.ast.ValueExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr)

Aggregations

VaporReference (com.google.api.generator.engine.ast.VaporReference)11 TypeNode (com.google.api.generator.engine.ast.TypeNode)10 Test (org.junit.Test)9 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)7 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)5 ReferenceConstructorExpr (com.google.api.generator.engine.ast.ReferenceConstructorExpr)5 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)4 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)3 Variable (com.google.api.generator.engine.ast.Variable)3 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)2 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)2 SuperObjectValue (com.google.api.generator.engine.ast.SuperObjectValue)2 HttpJsonOperationSnapshotCallable (com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable)1 OperationCallable (com.google.api.gax.rpc.OperationCallable)1 UnaryCallable (com.google.api.gax.rpc.UnaryCallable)1 AnnotationNode (com.google.api.generator.engine.ast.AnnotationNode)1 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)1 LogicalOperationExpr (com.google.api.generator.engine.ast.LogicalOperationExpr)1 Statement (com.google.api.generator.engine.ast.Statement)1 ThisObjectValue (com.google.api.generator.engine.ast.ThisObjectValue)1