Open somethingvague opened 5 months ago
This unpleasant diff appears to fix the issue (all tests pass). Unsure what the idiomatic ways to solve the underlying issues are https://github.com/openrewrite/rewrite/commit/4561fa4787742081557595858ee9be2e667e39de
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 JavaType
not being Unknown
i.e. somepkg.RealClass
is a known type but somepkg.other
(as part of a package) is not. This works in our setup but it does not work in the tests since somepkg.RealClass
is not on the class path and is therefore Unknown
.
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.
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.