-
Notifications
You must be signed in to change notification settings - Fork 367
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
Don't modify package declaration of siblings in ChangeType #4184
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for getting this started. Helpful to know we might now inadvertently make changes, and a good start at getting that resolved. I've added a note about the use of cursor messaging over mutable fields; I hope that's clear enough. If not do let us know!
rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good ; quick suggestion to rename the message key and variable, as path can mean the source file path too, which might be confusing.
rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved already; let me know how you feel about those suggestions and then we can get this merged.
Co-authored-by: Tim te Beek <[email protected]>
Should be all good 👍 |
Thanks a lot for the quick turn around on this; really helpful to get this sorted. I'll merge as soon as the tests pass and from there it'll become available in our snapshot versions until the next release, typically in a week or two. |
Hmm; seems two other tests have started failing; This might need some work still. 🤔 rewrite/rewrite-java-test/src/test/java/org/openrewrite/java/ChangeTypeTest.java Lines 1310 to 1332 in 2988966
rewrite/rewrite-java-test/src/test/java/org/openrewrite/java/ChangeTypeTest.java Lines 1426 to 1449 in 2988966
|
Hmm that's strange, they run and pass locally, both individually through IntelliJ and the full module via |
I did see them fail for me locally; I've triggered the tests to run again to see if that shows any difference. |
After switching machines I got the same lol, a fresh clone might have done it as well. In any case, I'm not sure I understand the |
Oh wow, I'd never noticed the Java docs on those methods; they seem to have been added deliberately, although I'd always taken those to mean the source paths before the recipe is run. rewrite/rewrite-test/src/main/java/org/openrewrite/test/SourceSpec.java Lines 108 to 124 in 2122964
We have other mechanisms to verify the source path is changed after a recipe run, which hints at the JavaDoc above being wrong.
So with that, the The The With that I think it would be best if we don't change the behavior of any of the existing cases, and maybe even fix the confusing JavaDocs. What are your thoughts on the same? |
That makes sense, thanks for the help! I pushed a commit here with how I'd go about fixing them, let me know if that should be a separate PR. The fix for the jd and the Though for the jd, I don't know the other uses, so let me know if "before" isn't correct either |
Thanks for the quick work; I had a slightly different idea come to mind after I'd already replied above; I should have updated my comment but was in the middle of other work. Before any of your changes, we handled the cases where there's multiple classes in a single compilation unit (file) and changed their package and source path if the recipe indicates that's necessary. The The issue you've reported, and are tackling here is a different variation: there's again two classes in the same package, but in different compilation units (files). That's where the recipe up to now appears to have been making incorrect changes, based on the new test you added where the sibling in a different file was changed as well. I think ideally we don't modify the tests we had before, and keep their behavior the same (unless we feel that's incorrect), and instead work out how to get the new test to pass by handling the above cases separately: sibling classes in the same compilation unit versus in different compilation units. And note that I'm certainly not trying to complicate the work you're doing! It's much appreciated; we're both learning what the recipe did before, and how that relates to what we'd like it to do going forward, and hope we agree on the approach. |
Source path and package declaration technically do not have to match, so this instead only looks for fully qualified class names
Ah I see now. Technically the provided and expected results aren't invalid Java code, but in practice you get misplaced class files that don't match their package declaration before compilation, which doesn't seem to be part of the linked issues (the provided class in An alternative to checking the source path for the sibling fix (as pushed now) would be to go through the classes in JavaSourceFile to check their fully qualified names, ignoring the actual source path. That should work and makes all tests pass, but I'm not sure of other implications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for working through all these iterations. I think this now works as we'd like it to.
What's changed?
ChangeClassDefinition
inChangeType
previously changed package declaration of sibling types, this PR restricts these to only the classes that should actually be changedWhat's your motivation?
Closes #4182
Anything in particular you'd like reviewers to focus on?
I'm not exactly sure as to whether this is the proper way to do it (tracking required modification in JavaSourceFile visits), but at the very least this should show what the root cause is. And I suppose this breaks the immutability ruleshould be addressed nowChecklist