Skip to content

Commit

Permalink
Add new test and fix (openrewrite#4672)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdebruin authored and MBoegers committed Dec 18, 2024
1 parent 2099691 commit 3b6066f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,41 @@ public class A {
);
}

@Test
void addArrayInputInAnnotationAttributeEmptyBraces() {
rewriteRun(
spec -> spec.recipe(new AddOrUpdateAnnotationAttribute(
"org.example.Foo",
"array",
"newTest1,newTest2",
false)),
java(
"""
package org.example;
public @interface Foo {
String[] array() default {};
}
"""
),
java(
"""
import org.example.Foo;
@Foo()
public class A {
}
""",
"""
import org.example.Foo;
@Foo(array = {"newTest1", "newTest2"})
public class A {
}
"""
)
);
}

@Test
void removeArrayInputInAnnotationAttribute() {
rewriteRun(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public J.Annotation visitAnnotation(J.Annotation a, ExecutionContext ctx) {

String newAttributeValue = maybeQuoteStringArgument(attributeName, attributeValue, a);
List<Expression> currentArgs = a.getArguments();
if (currentArgs == null || currentArgs.isEmpty()) {
if (currentArgs == null || currentArgs.isEmpty() || currentArgs.get(0) instanceof J.Empty) {
if (newAttributeValue == null) {
return a;
}
Expand Down

0 comments on commit 3b6066f

Please sign in to comment.