diff --git a/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java b/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java index 37dd4a5733..be95e6dcdc 100644 --- a/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java +++ b/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java @@ -166,6 +166,9 @@ public void visit(ScopeNode scope) { @Override public void visit(AnnotationNode annotation) { annotation.type().accept(this); + if (annotation.descriptionExprs() != null) { + expressions(annotation.descriptionExprs()); + } } @Override diff --git a/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java b/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java index 865f505a62..26bc5a015f 100644 --- a/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java +++ b/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java @@ -62,6 +62,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.lang.annotation.Repeatable; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -390,6 +391,43 @@ public void writeVariableExprImports_withAnnotations() { writerVisitor.write()); } + @Test + public void writeVariableExprImports_annotationsWithDescription() { + Variable variable = + Variable.builder() + .setName("expr") + .setType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))) + .build(); + + VariableExpr annotationDescription = + VariableExpr.builder() + .setVariable(Variable.builder().setType(TypeNode.CLASS_OBJECT).setName("class").build()) + .setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(List.class))) + .build(); + + // Constructs with annotation @Repeatable(List.class) + VariableExpr variableExpr = + VariableExpr.builder() + .setVariable(variable) + .setIsDecl(true) + .setAnnotations( + Arrays.asList( + AnnotationNode.builder() + .setType( + TypeNode.withReference(ConcreteReference.withClazz(Repeatable.class))) + .setDescription(annotationDescription) + .build())) + .build(); + + variableExpr.accept(writerVisitor); + assertEquals( + LineFormatter.lines( + "import com.google.api.generator.engine.ast.Expr;\n", + "import java.lang.annotation.Repeatable;\n", + "import java.util.List;\n\n"), + writerVisitor.write()); + } + @Test public void writeAnonymousClassExprImports() { // [Constructing] Function, MethodDefinition>