Skip to content

Commit

Permalink
fix(ast): update import generation to cover annotation parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
emmileaf committed Jan 4, 2023
1 parent 345b3c4 commit d59b40c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<List<IOException>, MethodDefinition>
Expand Down

0 comments on commit d59b40c

Please sign in to comment.