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