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