Search in sources :

Example 56 with Variable

use of com.google.api.generator.engine.ast.Variable in project gapic-generator-java by googleapis.

the class JavaWriterVisitorTest method writeVariableExpr_nestedReference.

@Test
public void writeVariableExpr_nestedReference() {
    Variable variable = Variable.builder().setName("x").setType(TypeNode.STRING_ARRAY).build();
    VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).build();
    Variable subVariable = Variable.builder().setName("someStringField").setType(TypeNode.STRING).build();
    variableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(variableExpr).build();
    subVariable = Variable.builder().setName("anotherStringField").setType(TypeNode.STRING).build();
    variableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(variableExpr).build();
    subVariable = Variable.builder().setName("lengthField").setType(TypeNode.INT).build();
    variableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(variableExpr).build();
    variableExpr.accept(writerVisitor);
    assertEquals("x.someStringField.anotherStringField.lengthField", 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 57 with Variable

use of com.google.api.generator.engine.ast.Variable in project gapic-generator-java by googleapis.

the class JavaWriterVisitorTest method writeNewObjectExpr_withMethodExprArgs.

@Test
public void writeNewObjectExpr_withMethodExprArgs() {
    // isGeneric() is false, and generics() is empty.
    // [Constructing] `new IOException(message, cause())` and `cause()` is a method invocation.
    TypeNode type = TypeNode.withReference(ConcreteReference.withClazz(IOException.class));
    Variable message = Variable.builder().setName("message").setType(TypeNode.STRING).build();
    VariableExpr msgExpr = VariableExpr.builder().setVariable(message).build();
    MethodInvocationExpr causeExpr = MethodInvocationExpr.builder().setMethodName("cause").setReturnType(TypeNode.withReference(ConcreteReference.withClazz(Throwable.class))).build();
    NewObjectExpr newObjectExpr = NewObjectExpr.builder().setType(type).setArguments(Arrays.asList(msgExpr, causeExpr)).build();
    newObjectExpr.accept(writerVisitor);
    assertEquals("new IOException(message, cause())", writerVisitor.write());
}
Also used : Variable(com.google.api.generator.engine.ast.Variable) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) IOException(java.io.IOException) Test(org.junit.Test)

Example 58 with Variable

use of com.google.api.generator.engine.ast.Variable in project gapic-generator-java by googleapis.

the class JavaWriterVisitorTest method writeVariableExpr_basicReferenceWithModifiersSet.

@Test
public void writeVariableExpr_basicReferenceWithModifiersSet() {
    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).setScope(ScopeNode.PUBLIC).setIsFinal(true).setIsStatic(true).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)

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