Skip to content

Commit

Permalink
ReplaceConstantWithAnotherConstant fails to replace field annotatio…
Browse files Browse the repository at this point in the history
…n arguments (#3448)

* chore: add testcase to reproduce field replacement issue

Note: this only applicable if the field constant is wrapped in curly braces

* Reduce reproduction test for debugger step through

* Merge main and update example

---------

Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: Knut Wannheden <[email protected]>
  • Loading branch information
3 people authored Nov 26, 2023
1 parent ff791fd commit 931c734
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import static org.openrewrite.java.Assertions.java;

public class ReplaceConstantWithAnotherConstantTest implements RewriteTest {
class ReplaceConstantWithAnotherConstantTest implements RewriteTest {

@Test
void replaceConstantInAnnotation() {
Expand Down Expand Up @@ -62,6 +62,33 @@ void foo() {
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite/pull/3448")
void replaceConstantInCurlyBracesInAnnotation() {
rewriteRun(
spec -> spec.recipe(new ReplaceConstantWithAnotherConstant("java.io.File.pathSeparator", "java.io.File.separator"))
.parser(JavaParser.fromJavaVersion().classpath("guava")),
java(
"""
import java.io.File;
class Test {
@SuppressWarnings({File.pathSeparator})
private String bar;
}
""",
"""
import java.io.File;
class Test {
@SuppressWarnings({File.separator})
private String bar;
}
"""
)
);
}

@Test
void replaceConstant() {
rewriteRun(
Expand Down

0 comments on commit 931c734

Please sign in to comment.