Commit a922f22
authored
Fix GroovyParserVisitor crash on multi-variable field declarations (#7467)
* Fix `GroovyParserVisitor` crash on multi-variable field declarations
Groovy emits a separate `FieldNode` for each variable in a multi-variable
field declaration (e.g., `final String a, b`). The parser was treating each
one as a complete declaration and re-consuming the modifiers and type tokens,
desynchronizing the cursor and eventually throwing `StringIndexOutOfBoundsException`
when parsing later nodes.
Detect continuation fields in `visitVariableField` and emit a `MultiVariable`
marker with an empty type expression, mirroring the existing handling for
local multi-variable declarations like `def a = 1, b = 2`.
* Simplify multi-variable field handling by reusing `maybeMultiVariable`
* Keep `maybeMultiVariable` in `RewriteGroovyVisitor`
Call it through the existing `visitor` instance from `visitVariableField`
to avoid displacing the `sourceBefore` javadoc.
* Revert stray whitespace change in `ConstructorTest`1 parent 8912b00 commit a922f22
2 files changed
Lines changed: 28 additions & 4 deletions
File tree
- rewrite-groovy/src
- main/java/org/openrewrite/groovy
- test/java/org/openrewrite/groovy/tree
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
586 | 586 | | |
587 | 587 | | |
588 | 588 | | |
589 | | - | |
590 | | - | |
591 | | - | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
592 | 602 | | |
593 | 603 | | |
594 | 604 | | |
| |||
612 | 622 | | |
613 | 623 | | |
614 | 624 | | |
615 | | - | |
| 625 | + | |
616 | 626 | | |
617 | 627 | | |
618 | 628 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
128 | 142 | | |
129 | 143 | | |
130 | 144 | | |
| |||
0 commit comments