use of com.google.api.generator.engine.ast.ReferenceConstructorExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeReferenceConstructorExprImports_withArgs.
@Test
public void writeReferenceConstructorExprImports_withArgs() {
VaporReference ref = VaporReference.builder().setName("Student").setPakkage("com.google.example.v1").build();
TypeNode classType = TypeNode.withReference(ref);
VariableExpr streamVarExpr = VariableExpr.builder().setVariable(createVariable("stream", TypeNode.withReference(ConcreteReference.withClazz(LongStream.class)))).build();
ReferenceConstructorExpr referenceConstructorExpr = ReferenceConstructorExpr.thisBuilder().setArguments(Arrays.asList(streamVarExpr)).setType(classType).build();
referenceConstructorExpr.accept(writerVisitor);
}
use of com.google.api.generator.engine.ast.ReferenceConstructorExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeReferenceConstructorExprImports_basic.
@Test
public void writeReferenceConstructorExprImports_basic() {
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);
assertEquals("import com.google.example.v1.Parent;\n\n", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.ReferenceConstructorExpr 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.ReferenceConstructorExpr 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.ReferenceConstructorExpr 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