Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maybeAddImport adds import although all references are fully qualified #4261

Open
Philzen opened this issue Jun 17, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@Philzen
Copy link

Philzen commented Jun 17, 2024

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
@Philzen Philzen added the bug Something isn't working label Jun 17, 2024
@timtebeek
Copy link
Contributor

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. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants