Search in sources :

Example 51 with Variable

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());
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) UnaryOperationExpr(com.google.api.generator.engine.ast.UnaryOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) InstanceofExpr(com.google.api.generator.engine.ast.InstanceofExpr) CastExpr(com.google.api.generator.engine.ast.CastExpr) ArithmeticOperationExpr(com.google.api.generator.engine.ast.ArithmeticOperationExpr) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) AssignmentOperationExpr(com.google.api.generator.engine.ast.AssignmentOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) List(java.util.List) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 52 with Variable

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());
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Test(org.junit.Test)

Example 53 with Variable

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());
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Test(org.junit.Test)

Example 54 with Variable

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());
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Test(org.junit.Test)

Example 55 with Variable

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());
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) Reference(com.google.api.generator.engine.ast.Reference) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) VaporReference(com.google.api.generator.engine.ast.VaporReference) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) Test(org.junit.Test)

Aggregations

Variable (com.google.api.generator.engine.ast.Variable)58 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)54 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)37 Test (org.junit.Test)35 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)34 TypeNode (com.google.api.generator.engine.ast.TypeNode)29 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)26 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)25 Expr (com.google.api.generator.engine.ast.Expr)24 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)20 AnonymousClassExpr (com.google.api.generator.engine.ast.AnonymousClassExpr)19 CastExpr (com.google.api.generator.engine.ast.CastExpr)17 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)17 ReturnExpr (com.google.api.generator.engine.ast.ReturnExpr)17 TernaryExpr (com.google.api.generator.engine.ast.TernaryExpr)17 ThrowExpr (com.google.api.generator.engine.ast.ThrowExpr)17 List (java.util.List)17 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)16 PrimitiveValue (com.google.api.generator.engine.ast.PrimitiveValue)16 ArrayList (java.util.ArrayList)16