use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeNewObjectExprImports_withArgs.
@Test
public void writeNewObjectExprImports_withArgs() {
// [Constructing] `new FileOutputStream(File file)` and the argument needs to be imported.
ConcreteReference fileOutputStreamRef = ConcreteReference.withClazz(FileOutputStream.class);
ConcreteReference fileRef = ConcreteReference.withClazz(File.class);
Variable fileVar = Variable.builder().setName("file").setType(TypeNode.withReference(fileRef)).build();
VariableExpr fileExpr = VariableExpr.builder().setVariable(fileVar).build();
NewObjectExpr newObjectExpr = NewObjectExpr.builder().setType(TypeNode.withReference(fileOutputStreamRef)).setArguments(Arrays.asList(fileExpr)).build();
newObjectExpr.accept(writerVisitor);
assertEquals(LineFormatter.lines("import java.io.File;\n", "import java.io.FileOutputStream;\n\n"), writerVisitor.write());
}
use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeVariableExprImports_reference.
@Test
public void writeVariableExprImports_reference() {
Variable variable = Variable.builder().setName("expr").setType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))).build();
VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).build();
Variable subVariable = Variable.builder().setName("assignExpr").setType(TypeNode.withReference(ConcreteReference.withClazz(AssignmentExpr.class))).build();
variableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(variableExpr).build();
variableExpr.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 writeVariableExprImports_nestedReference.
@Test
public void writeVariableExprImports_nestedReference() {
Variable variable = Variable.builder().setName("expr").setType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))).build();
VariableExpr variableExpr = VariableExpr.builder().setVariable(variable).build();
Variable subVariable = Variable.builder().setName("assignExpr").setType(TypeNode.withReference(ConcreteReference.withClazz(AssignmentExpr.class))).build();
variableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(variableExpr).build();
subVariable = Variable.builder().setName("anotherExpr").setType(TypeNode.withReference(ConcreteReference.withClazz(VariableExpr.class))).build();
variableExpr = VariableExpr.builder().setVariable(subVariable).setExprReferenceExpr(variableExpr).build();
variableExpr.accept(writerVisitor);
assertEquals(LineFormatter.lines("import com.google.api.generator.engine.ast.AssignmentExpr;\n", "import com.google.api.generator.engine.ast.Expr;\n", "import com.google.api.generator.engine.ast.VariableExpr;\n\n"), writerVisitor.write());
}
use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeMethodDefinitionImports_templatedMixedNamesAndTypes.
@Test
public void writeMethodDefinitionImports_templatedMixedNamesAndTypes() {
Reference mapRef = ConcreteReference.withClazz(Map.class);
List<VariableExpr> arguments = Arrays.asList(VariableExpr.builder().setVariable(createVariable("x", TypeNode.withReference(mapRef))).setIsDecl(true).setTemplateObjects(Arrays.asList("K", TypeNode.withReference(ConcreteReference.withClazz(AssignmentExpr.class)))).build(), VariableExpr.builder().setVariable(createVariable("y", TypeNode.withReference(mapRef))).setIsDecl(true).setTemplateObjects(Arrays.asList("T", "V")).build());
TypeNode returnType = TypeNode.withReference(mapRef);
MethodDefinition methodDefinition = MethodDefinition.builder().setName("close").setScope(ScopeNode.PUBLIC).setReturnType(returnType).setTemplateNames(Arrays.asList("T", "K", "V")).setReturnTemplateNames(Arrays.asList("K", "V")).setArguments(arguments).setReturnExpr(MethodInvocationExpr.builder().setMethodName("foobar").setReturnType(returnType).build()).build();
methodDefinition.accept(writerVisitor);
assertEquals(LineFormatter.lines("import com.google.api.generator.engine.ast.AssignmentExpr;\n", "import java.util.Map;\n\n"), writerVisitor.write());
}
use of com.google.api.generator.engine.ast.VariableExpr in project gapic-generator-java by googleapis.
the class ImportWriterVisitorTest method writeVariableExprImports_staticReference.
@Test
public void writeVariableExprImports_staticReference() {
VariableExpr variableExpr = VariableExpr.builder().setVariable(Variable.builder().setType(TypeNode.withReference(ConcreteReference.withClazz(AssignmentExpr.class))).setName("AN_ASSIGN_EXPR").build()).setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(TypeNode.class))).build();
variableExpr.accept(writerVisitor);
assertEquals(LineFormatter.lines("import com.google.api.generator.engine.ast.AssignmentExpr;\n", "import com.google.api.generator.engine.ast.TypeNode;\n\n"), writerVisitor.write());
}
Aggregations