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
ChangePackage recipe does not handle package names with single element #4142
Comments
This unpleasant diff appears to fix the issue (all tests pass). Unsure what the idiomatic ways to solve the underlying issues are 4561fa4 Edit: is it unsuitable because it also changes imports for subpackages |
Thanks for the detailed report! Indeed perhaps a too simplistic assumption that there would always be a dot in a package. I'll try to fit in a more detailed look next week, although you're welcome to iterate on a better solution if you feel there's more to it. :) |
Thanks for picking this up. I have an even worse diff which relies on the Off topic, but we still cannot use the recipe with a fix for this issue because we do not want to move files - they have already been moved to a sane place in our monorepo. How would you feel about a new option to not change the file paths? Happy to contribute if you think that'd be useful for others too. |
Thanks for the offer to contribute such an addition; I've not come across such a requirement before, which makes me hesitant to adopt and maintain that going forward. Instead, I propose to explore running ChangePackage as you would normally, potentially followed by Rename a file. You can bundle that into a recipe that you use internally, and package that with a fork of this template: https://github.com/moderneinc/rewrite-recipe-starter |
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
Initially observed the issue when running in a custom Bazel setup but reproduced on an OpenRewrite fork off the main branch with a new test.
Fork
Example Test
What is the smallest, simplest way to reproduce the problem?
The test itself attempts to change a package from
somepkg
toorg.openrewrite.somepkg
but imports are not updated.The issue stems from
visitFieldAccess
in theChangePackage
recipe which invokesisFullyQualifiedClassReference
on theFieldAccess
, passing in the old package name. This method expects there to be a.
in the value passed in. It's not clear to me what the fix is sinceisFullyQualifiedClassReference
is expecting a class reference, not a package name.Are you interested in [contributing a fix to OpenRewrite
Sure, once I'm more comfortable with the codebase.
The text was updated successfully, but these errors were encountered: