Add RemovePrivateFieldUnderscores recipe
What's changed?
This recipe removes prefix or suffix underscores from private class field names. This helps enforce modern Java coding standards.
For clarity and consistency, the recipe also adds a qualifier to all updated field accesses. This prevents ambiguity with local variables and ensures a uniform style throughout the class.
What's your motivation?
- Fixes #630
Checklist
- [X] I've added unit tests to cover both positive and negative cases
- [X] I've read and applied the recipe conventions and best practices
- [X] I've used the IntelliJ IDEA auto-formatter on affected files
Let us know if you'd need any guidance @jhl221123 ! Perhaps this session could help you get started: https://www.moderne.ai/content-library/introduction-to-openrewrite
Another case:
String foo(String bar) {
String _bar = bang(bar);
// ... do something else with bar ...
return _bar;
}
In this case, I would expect no change.
Thanks for the detailed feedback, @dsgrieve. I believe I've addressed everything now. Ready for another look when you have a moment.
Sorry. I keep stumbling upon use cases. Be aware of JEP 456 which allows an _ to be used as an un-named variable.
@dsgrieve No problem at all, and thank you for catching these important edge cases! I've pushed an update to handle it. Please let me know if you spot anything else.
Nice work on the recipe. Don't worry about the timing, we are not in a hurry in any way ;)
This PR is stale because it has been open for 90 days with no activity. Remove stale label or comment or this will be closed in two weeks. PRs may be reopened when there is renewed interest.