openrewrite / openrewrite/rewrite
`maybeAddImport` adds import although all references are fully qualified
Open
Nobody has claimed this yet.
bug
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 571
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Visitor's maybeAddImport("org.junit.jupiter.api.Test") call and reproduce the issue with the isMigratedToMethods_whenFullyQualified test shown in the report. Trace how fully qualified references are detected; done means the shown test no longer adds an import when every reference remains fully qualified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100