You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the smallest, simplest way to reproduce the problem?
Run this test, it will failed, because currently we didn't consider the import conflict. For this case, already has a foo1.Bar so we cannot add another foo2.Bar
@TestvoidshouldFullyQualifyWhenNewTypeIsAmbiguous() {
rewriteRun(
spec -> spec.recipe(newReplaceConstantWithAnotherConstant("foo1.Bar.QUX1", "foo2.Bar.QUX1")),
java(
""" package foo1; public class Bar { public static final String QUX1 = "QUX1_FROM_FOO1"; public static final String QUX2 = "QUX1_FROM_FOO2"; } """
),
java(
""" package foo2; public class Bar { public static final String QUX1 = "QUX1_FROM_FOO1"; } """
),
java(
""" import foo1.Bar; class Test { void a() { System.out.println(Bar.QUX1); System.out.println(Bar.QUX2); } } """,
""" import foo1.Bar; class Test { void a() { System.out.println(foo2.Bar.QUX1); System.out.println(Bar.QUX2); } } """
)
);
}
What is the full stack trace of any errors you encountered?
Unexpected result in "Test.java":
diff --git a/Test.java b/Test.java
index 58f9eb2..67b9d58 100644
--- a/Test.java
+++ b/Test.java
@@ -1,8 +1,9 @@
import foo1.Bar;
+import foo2.Bar;
class Test {
void a() {
- System.out.println(foo2.Bar.QUX1);
+ System.out.println(Bar.QUX1);
System.out.println(Bar.QUX2);
}
}
\ No newline at end of file
]
expected:
"import foo1.Bar;
class Test {
void a() {
System.out.println(foo2.Bar.QUX1);
System.out.println(Bar.QUX2);
}
}"
but was:
"import foo1.Bar;
import foo2.Bar;
class Test {
void a() {
System.out.println(Bar.QUX1);
System.out.println(Bar.QUX2);
}
}"
<Click to see difference>
at org.openrewrite.test.RewriteTest.assertContentEquals(RewriteTest.java:621)
at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:510)
at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:130)
at org.openrewrite.java.ReplaceConstantWithAnotherConstantTest.shouldFullyQualifyWhenNewTypeIsAmbiguous(ReplaceConstantWithAnotherConstantTest.java:281)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
What version of OpenRewrite are you using?
I am using the latest rewrite (8.48.1)
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
What is the smallest, simplest way to reproduce the problem?
Run this test, it will failed, because currently we didn't consider the import conflict. For this case, already has a
foo1.Bar
so we cannot add anotherfoo2.Bar
What did you expect to see?
What did you see instead?
What is the full stack trace of any errors you encountered?
Are you interested in contributing a fix to OpenRewrite?
Sure.
The text was updated successfully, but these errors were encountered: