Skip to content

Commit 27b9c64

Browse files
committed
Fix AddOrUpdateAnnotation recipe changing implicit value into explicit value in annotations with arrays
1 parent 2a0fad1 commit 27b9c64

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

rewrite-java-test/src/test/java/org/openrewrite/java/AddOrUpdateAnnotationAttributeTest.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,43 @@ public class A {
536536
);
537537
}
538538

539+
@Test
540+
void arrayInAnnotationValueAttribute() {
541+
rewriteRun(
542+
spec -> spec.recipe(new AddOrUpdateAnnotationAttribute(
543+
"org.example.Foo",
544+
null,
545+
"newTest",
546+
null,
547+
false,
548+
false)),
549+
java(
550+
"""
551+
package org.example;
552+
public @interface Foo {
553+
String[] value() default {};
554+
}
555+
"""
556+
),
557+
java(
558+
"""
559+
import org.example.Foo;
560+
561+
@Foo({"oldTest"})
562+
public class A {
563+
}
564+
""",
565+
"""
566+
import org.example.Foo;
567+
568+
@Foo({"newTest"})
569+
public class A {
570+
}
571+
"""
572+
)
573+
);
574+
}
575+
539576
@Test
540577
void arrayInputMoreThanOneInAnnotationAttribute() {
541578
rewriteRun(
@@ -573,6 +610,43 @@ public class A {
573610
);
574611
}
575612

613+
@Test
614+
void arrayInputMoreThanOneInAnnotationValueAttribute() {
615+
rewriteRun(
616+
spec -> spec.recipe(new AddOrUpdateAnnotationAttribute(
617+
"org.example.Foo",
618+
null,
619+
"newTest1,newTest2",
620+
null,
621+
false,
622+
false)),
623+
java(
624+
"""
625+
package org.example;
626+
public @interface Foo {
627+
String[] value() default {};
628+
}
629+
"""
630+
),
631+
java(
632+
"""
633+
import org.example.Foo;
634+
635+
@Foo({"oldTest"})
636+
public class A {
637+
}
638+
""",
639+
"""
640+
import org.example.Foo;
641+
642+
@Foo({"newTest1", "newTest2"})
643+
public class A {
644+
}
645+
"""
646+
)
647+
);
648+
}
649+
576650
@Test
577651
void addArrayInputInAnnotationAttribute() {
578652
rewriteRun(

rewrite-maven/src/test/java/org/openrewrite/maven/RemoveUnusedPropertiesTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,57 @@ void keepsUsedProperty() {
257257
);
258258
}
259259

260+
@Test
261+
void checkPlugin() {
262+
rewriteRun(
263+
pomXml(
264+
"""
265+
<?xml version="1.0" encoding="UTF-8"?>
266+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
267+
<modelVersion>4.0.0</modelVersion>
268+
<groupId>org.sample</groupId>
269+
<artifactId>sample</artifactId>
270+
<version>1.0.0</version>
271+
272+
<properties>
273+
<versionx>6.0.0</versionx>
274+
<bar>xyz</bar>
275+
</properties>
276+
277+
<plugins>
278+
<plugin>
279+
<groupId>org.openrewrite.maven</groupId>
280+
<artifactId>rewrite-maven-plugin</artifactId>
281+
<version>${versionx}</version>
282+
</plugin>
283+
</plugins>
284+
</project>
285+
""",
286+
"""
287+
<?xml version="1.0" encoding="UTF-8"?>
288+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
289+
<modelVersion>4.0.0</modelVersion>
290+
<groupId>org.sample</groupId>
291+
<artifactId>sample</artifactId>
292+
<version>1.0.0</version>
293+
294+
<properties>
295+
<versionx>6.0.0</versionx>
296+
</properties>
297+
298+
<plugins>
299+
<plugin>
300+
<groupId>org.openrewrite.maven</groupId>
301+
<artifactId>rewrite-maven-plugin</artifactId>
302+
<version>${versionx}</version>
303+
</plugin>
304+
</plugins>
305+
</project>
306+
"""
307+
)
308+
);
309+
}
310+
260311
@Test
261312
void catchesMultiplePropertyUsagesInSameElement() {
262313
rewriteRun(

0 commit comments

Comments
 (0)