Repository navigation
UnnecessarySemicolon: ignore generated members - #6445
ihabyehia-dev wants to merge 3 commits into
Conversation
| } else { | ||
| Tree next = tree.getMembers().get(i + 1); | ||
| if (!hasExplicitSource(next, state)) { | ||
| if (!hasExplicitSource(next, state) || isGenerated(next)) { |
There was a problem hiding this comment.
When Lombok appends generated accessors after the last explicit field, next is generated and this continue skips scanning the trailing gap to state.getEndPosition(tree) (so an actual extra ; after second won't be caught). Same thing if a generated member sits between two explicit members. Pre-filtering tree.getMembers() to explicit non-generated members before the loop handles both cases while keeping the enum-constant checks intact.
There was a problem hiding this comment.
Thank you for taking the time to review my contribution and for your valuable feedback.
I've updated the implementation to follow your suggestion, filtering explicit, non-generated members before iteration while preserving the enum-constant checks.
I've also added regression tests covering both scenarios you mentioned. All 17 targeted tests and the full Maven test suite passed locally.
I hope the revised implementation addresses your concerns. I'd be happy to make any further improvements if needed.
Thank you again for your time and guidance!
Keep declarations with source-written @generated annotations in the scan while excluding Lombok-injected members. Cover redundant semicolons between annotated fields and at the end of a class.
Fixes #6233
What changed
Filter class members with no explicit source or with an injected
@Generatedannotation before scanning for redundant semicolons. A declaration with@Generatedwritten in the source still marks a boundary for the scan. The scan stops at the first token other than a semicolon.Why
Lombok-generated getters and setters borrow source positions from fields and annotations. Treating those offsets as declaration boundaries can delete required semicolons or miss redundant ones. The revised scan preserves enum separators and handles extra semicolons between fields and at the end of a class.
Testing
mvn -pl core -am -Dtest=UnnecessarySemicolonTest -Dsurefire.failIfNoSpecifiedTests=false testpassed all 18 focused tests on JDK 25.@Generatedfields in a class with Lombok-generated getters. It fails on the previous commit.