Search in sources :

Example 1 with ReferenceConstructorExpr

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);
}
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 2 with ReferenceConstructorExpr

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());
}
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 3 with ReferenceConstructorExpr

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)");
}
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 4 with ReferenceConstructorExpr

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()");
}
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 5 with ReferenceConstructorExpr

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

ReferenceConstructorExpr (com.google.api.generator.engine.ast.ReferenceConstructorExpr)5 VaporReference (com.google.api.generator.engine.ast.VaporReference)5 TypeNode (com.google.api.generator.engine.ast.TypeNode)4 Test (org.junit.Test)4 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)3 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)1 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)1 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)1