`maybeAddImport` adds import although all references are fully qualified
Philzen opened this issue · comments
Philzen commented
I developing a recipe with OpenRewrite v8.27.1 and have this test:
@Test void isMigratedToMethods_whenFullyQualified() {
// language=java
rewriteRun(java(
"""
package de.foo.bar;
@org.testng.annotations.Test
public class BazTest {
public void shouldDoStuff() {
//
}
public void shouldDoMoreStuff() {
//
}
}
""",
"""
package de.foo.bar;
public class BazTest {
@org.junit.jupiter.api.Test
public void shouldDoStuff() {
//
}
@org.junit.jupiter.api.Test
public void shouldDoMoreStuff() {
//
}
}
"""
));
}
The Visitor under test contains a call to maybeAddImport("org.junit.jupiter.api.Test")
.
What did you expect to see?
No import added, as it is not necessary.
What did you see instead?
package de.foo.bar;
+import org.junit.jupiter.api.Test;
+
public class BazTest {
@org.junit.jupiter.api.Test
Tim te Beek commented
Hmm; that's odd. I'd have imagined we'd have seen such an issue before, although it could be that we just look to see if I type is used, and not if all usages are fully qualified. 🤔