Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -892,4 +892,50 @@ public class A {
)
);
}

@Test
void addAttributeToNestedAnnotationArray() {
rewriteRun(
spec -> spec.recipe(new AddOrUpdateAnnotationAttribute(
"org.example.Bar",
"attribute",
"",
null,
false)),
java(
"""
package org.example;
public @interface Foo {
Bar[] array() default {};
}
"""
),
java(
"""
package org.example;
public @interface Bar {
String attribute() default "";
}
"""
),
java(
"""
import org.example.Foo;
import org.example.Bar;

@Foo(array = { @Bar() })
public class A {
}
""",
"""
import org.example.Foo;
import org.example.Bar;

@Foo(array = { @Bar(attribute = "") })
public class A {
}
"""
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
public J.Annotation visitAnnotation(J.Annotation a, ExecutionContext ctx) {
J.Annotation original = super.visitAnnotation(a, ctx);
if (!TypeUtils.isOfClassType(a.getType(), annotationType)) {
return a;
return original;
}

String newAttributeValue = maybeQuoteStringArgument(attributeName, attributeValue, a);
Expand Down