-
Notifications
You must be signed in to change notification settings - Fork 362
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
Won't this remove a static method import if the class is not used? #3480
Comments
Hi @amirmv2006 ! When I don't quite know how you're running OpenRewrite, or how you've configured for instance the build plugins. That might factor in here. We usually ask folks to fill out this short form whenever they report issues, such that we have some of the context in which a problem occurs. Would you mind sharing those details such that we can better judge what might factor in here? I'm not sure in your case which recipe (out of the hundreds involved with a Spring Boot 3 migration) lead to calling We can't blindly not remove imports when there are missing types, as there are frequent cases where we would still like to make changes despite missing type attribution. You're also welcome to join our Slack if you'd rather discuss the details in a mostly synchronous chat. |
Hi @timtebeek, thanks for the prompt response!
I don't think so, the problem is with Junit 5's
I will edit the issue description to the format you've mentioned 🙏.
Here's my debugging path:
I'd also like to challenge the way |
Sorry, Lombok was actually the problem. I am using Lombok in the class under test, but was not using it in the test class of course. However, I think that was setting the AST parsing off. After "delomboking" the class under test, the recipe also worked out great 👍 |
Thanks for reporting back here! We're tracking support for Lombok in this issue, welcome to follow along there. And if there's anything else we can help with feel free to report here or join our Slack. |
Description
Applying the spring boot 3 migration script, I came across an issue where my static import of
assert*
methods are removed when they are actually in use. I couldn't create a snippet where this would be reproducible, but I can debug my project locally, and I narrowed it down to this line.rewrite/rewrite-java/src/main/java/org/openrewrite/java/RemoveImport.java
Line 140 in 53f8095
It's a bit confusing understanding of "what should happen", so bear with me if these questions are "obvious" 😅
RemoveImport
is called for a class withf.q.N
, should it remove static method imports from this class? For example should it removef.q.N.m
? IMHO, that shouldn't happen in the first place, becauseRemoveImport
doesn't necessarily mean the class is removed so all its static methods should also be removed... for example, ruleorg.openrewrite.java.testing.junit5.StaticImports
is removing the import for the Assertions class, and adding the import for its used static methods instead.org.openrewrite.java.internal.TypesInUse
is not detecting my imported static method usage.org.openrewrite.java.internal.TypesInUse.FindTypesInUse#visitMethodInvocation
is called, and passed method has correct name, butmethod.getMethodType()
isnull
, but I don't understand why.What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a multi-module project.
What is the smallest, simplest way to reproduce the problem?
What did you expect to see?
What did you see instead?
What is the full stack trace of any errors you encountered? No errors.
Are you interested in contributing a fix to OpenRewrite?
Yes but I don't know how to fix this.
The text was updated successfully, but these errors were encountered: