use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeRelationalOperationExpr_lessThan.
@Test
public void writeRelationalOperationExpr_lessThan() {
VariableExpr lhsExpr = VariableExpr.withVariable(createVariable("i", TypeNode.INT));
MethodInvocationExpr rhsExpr = MethodInvocationExpr.builder().setMethodName("getMaxNumber").setReturnType(TypeNode.INT).build();
RelationalOperationExpr lessThanWithExprs = RelationalOperationExpr.lessThanWithExprs(lhsExpr, rhsExpr);
lessThanWithExprs.accept(writerVisitor);
assertThat(writerVisitor.write()).isEqualTo("i < getMaxNumber()");
}
use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeInstanceofExprImports_basic.
@Test
public void writeInstanceofExprImports_basic() {
TypeNode exprType = TypeNode.withReference(ConcreteReference.withClazz(Expr.class));
TypeNode assignExprType = TypeNode.withReference(ConcreteReference.withClazz(AssignmentExpr.class));
Variable variable = Variable.builder().setName("x").setType(assignExprType).build();
VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).build();
InstanceofExpr expr = InstanceofExpr.builder().setExpr(variableExpr).setCheckType(exprType).build();
expr.accept(writerVisitor);
assertEquals(LineFormatter.lines("import com.google.api.generator.engine.ast.AssignmentExpr;\n", "import com.google.api.generator.engine.ast.Expr;\n\n"), writerVisitor.write());
}
use of com.google.api.generator.engine.ast.VariableExpr 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.VariableExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeVariableExprImports_wildcardType.
@Test
public void writeVariableExprImports_wildcardType() {
TypeNode wildcardListType = TypeNode.withReference(ConcreteReference.builder().setClazz(List.class).setGenerics(Arrays.asList(TypeNode.WILDCARD_REFERENCE)).build());
// Constructs `List<?> x`.
Variable variable = Variable.builder().setName("x").setType(wildcardListType).build();
VariableExpr variableExpr = VariableExpr.builder().setIsDecl(true).setVariable(variable).build();
variableExpr.accept(writerVisitor);
assertEquals("import java.util.List;\n\n", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeLogicalOperationExprImports.
@Test
public void writeLogicalOperationExprImports() {
MethodInvocationExpr lhsExpr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(UnaryOperationExpr.class))).setMethodName("isValid").setReturnType(TypeNode.BOOLEAN).build();
VariableExpr rhsExpr = VariableExpr.builder().setVariable(createVariable("isGood", TypeNode.BOOLEAN)).build();
LogicalOperationExpr logicalOperationExpr = LogicalOperationExpr.logicalAndWithExprs(lhsExpr, rhsExpr);
logicalOperationExpr.accept(writerVisitor);
assertEquals("import com.google.api.generator.engine.ast.UnaryOperationExpr;\n\n", writerVisitor.write());
}
Aggregations