use of com.google.api.generator.engine.ast.Variable in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeVariableExpr_wildcardTypeWithUpperBound.
@Test
public void writeVariableExpr_wildcardTypeWithUpperBound() {
TypeNode wildcardListType = TypeNode.withReference(ConcreteReference.builder().setClazz(List.class).setGenerics(Arrays.asList(ConcreteReference.wildcardWithUpperBound(ConcreteReference.withClazz(Expr.class)))).build());
Variable variable = Variable.builder().setName("x").setType(wildcardListType).build();
VariableExpr variableExpr = VariableExpr.builder().setIsDecl(true).setVariable(variable).build();
variableExpr.accept(writerVisitor);
assertEquals("List<? extends Expr> x", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.Variable in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeVariableExpr_basicReference.
@Test
public void writeVariableExpr_basicReference() {
Variable variable = Variable.builder().setName("x").setType(TypeNode.STRING_ARRAY).build();
VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).build();
Variable subVariable = Variable.builder().setName("length").setType(TypeNode.INT).build();
variableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(variableExpr).build();
variableExpr.accept(writerVisitor);
assertEquals("x.length", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.Variable in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeVariableExpr_nonDeclIgnoresModifiers.
@Test
public void writeVariableExpr_nonDeclIgnoresModifiers() {
Variable variable = Variable.builder().setName("x").setType(TypeNode.BOOLEAN).build();
VariableExpr expr = VariableExpr.builder().setVariable(variable).setScope(ScopeNode.PUBLIC).setIsStatic(true).setIsFinal(true).build();
expr.accept(writerVisitor);
assertEquals("x", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.Variable in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeVariableExpr_scopedDecl.
@Test
public void writeVariableExpr_scopedDecl() {
Variable variable = Variable.builder().setName("x").setType(TypeNode.INT).build();
VariableExpr expr = VariableExpr.builder().setVariable(variable).setScope(ScopeNode.PRIVATE).setIsDecl(true).build();
expr.accept(writerVisitor);
assertEquals("private int x", writerVisitor.write());
}
use of com.google.api.generator.engine.ast.Variable in project gapic-generator-java by googleapis.
the class JavaWriterVisitorTest method writeMethodInvocationExpr_genericWithArgs.
@Test
public void writeMethodInvocationExpr_genericWithArgs() {
Reference mapReference = ConcreteReference.builder().setClazz(HashMap.class).setGenerics(Arrays.asList(ConcreteReference.withClazz(String.class), ConcreteReference.withClazz(Integer.class))).build();
Reference outerMapReference = ConcreteReference.builder().setClazz(HashMap.class).setGenerics(Arrays.asList(mapReference, mapReference)).build();
Variable variable = Variable.builder().setType(TypeNode.INT).setName("anArg").build();
VariableExpr varExpr = VariableExpr.builder().setVariable(variable).build();
MethodInvocationExpr methodExpr = MethodInvocationExpr.builder().setMethodName("foobar").setGenerics(Arrays.asList(ConcreteReference.withClazz(String.class), ConcreteReference.withClazz(Double.class), TypeNode.WILDCARD_REFERENCE, outerMapReference)).setArguments(Arrays.asList(varExpr, varExpr, varExpr)).setExprReferenceExpr(varExpr).setReturnType(TypeNode.STRING).build();
Variable lhsVariable = Variable.builder().setType(TypeNode.STRING).setName("someStr").build();
VariableExpr lhsVarExpr = VariableExpr.builder().setVariable(lhsVariable).setIsDecl(true).setIsFinal(true).build();
AssignmentExpr assignExpr = AssignmentExpr.builder().setVariableExpr(lhsVarExpr).setValueExpr(methodExpr).build();
assignExpr.accept(writerVisitor);
assertEquals("final String someStr = anArg.<String, Double, ?, HashMap<HashMap<String, Integer>," + " HashMap<String, Integer>>>foobar(anArg, anArg, anArg)", writerVisitor.write());
}
Aggregations