-
Notifications
You must be signed in to change notification settings - Fork 466
Fix whitespace preservation when removing access modifiers #5905
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
Fix whitespace preservation when removing access modifiers #5905
Conversation
Properly merge whitespace and comments from removed access modifier with the next modifier when changing to package-private access level. - Add Space merging logic for removed modifiers - Handle comment relocation during modifier removal - Add test for line comment movement
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.
Some suggestions could not be made:
- rewrite-maven/src/main/java/org/openrewrite/maven/tree/Dependency.java
- lines 26-26
rewrite-java-test/src/test/java/org/openrewrite/java/ChangeMethodAccessLevelTest.java
Outdated
Show resolved
Hide resolved
…hodAccessLevelTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
Some suggestions could not be made:
- rewrite-java/src/test/java/org/openrewrite/java/search/HasBuildToolVersionTest.java
- lines 21-21
- lines 36-36
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 for the helpful fix here @dongwooooooo !
…te#5905) * fix: preserve spacing when removing access modifiers Properly merge whitespace and comments from removed access modifier with the next modifier when changing to package-private access level. - Add Space merging logic for removed modifiers - Handle comment relocation during modifier removal - Add test for line comment movement * Update rewrite-java-test/src/test/java/org/openrewrite/java/ChangeMethodAccessLevelTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Slight polish --------- Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tim te Beek <[email protected]>
What's changed?
Fixed whitespace and comment handling when changing method access level to package-private. The removed access modifier's Space (whitespace and comments) is now properly merged with the next modifier to maintain consistent formatting.
What's your motivation?
Resolves spacing issues where the auto-formatter doesn't influence spacing when comments are involved. This was causing inconsistent formatting when access modifiers were removed, particularly when line comments were present.
Referenced issue pattern can be seen in rewrite-spring's BeanMethodsNotPublicTest where dataSource3 bean formatting was problematic.
Anything in particular you'd like reviewers to focus on?
publicToPackagePrivateMovesLineComment()
which covers the specific scenario where line comments need to be relocatedHave you considered any alternatives or workarounds?
Considered relying solely on auto-formatting, but as noted in the issue, auto-formatter doesn't handle spacing when comments are involved. The current approach manually preserves the spacing structure by merging Space objects.
Checklist