leonard84 opened a new pull request, #2686:
URL: https://github.com/apache/groovy/pull/2686

   This backports the eight decompiler-fidelity fixes from master (#2682, 
commit `4b27025962`) to `GROOVY_3_0_X`. `AstNodeToScriptVisitor` rendered 
several constructs so they did not round-trip; each fix is localized to one 
visitor method:
   
   1. Nested generic type arguments dropped (`Map<String, List<Integer>>` → 
`Map<String, List>`) — `visitGenerics` recurses into concrete args.
   2. Range bound exclusions dropped — `visitRangeExpression`.
   3. Elvis rendered as a duplicated ternary (`c ?: d` → `c ? c : d`, 
evaluating `c` twice) — `visitShortTernaryExpression` emits `?:`.
   4. Attribute access lost the at-sign (`obj.@f` → `obj.f`) — 
`visitPropertyExpression` emits `.@` for an `AttributeExpression`.
   5. Explicit zero-arg closures lost the arrow (`{ -> ... }` → `{ ... }`) — 
`visitClosureExpression` distinguishes a null parameter list from 
`Parameter.EMPTY_ARRAY`.
   6. Safe index access lost safe navigation (`list?[0]` → `list[0]`) — 
`visitBinaryExpression`.
   7. Numeric literal type suffixes dropped (`42L/2.5f/3.5d/10G`) — 
`visitConstantExpression` re-appends `L/F/D/G`.
   8. Explicit method-call type arguments dropped 
(`Collections.<String>emptyList()`) — `visitMethodCallExpression`.
   
   One regression test per defect (GroovyTestCase style, matching the existing 
test class). Existing tests reconciled to the corrected output: 
`testTernaryOperaters` (elvis), `testGenericsInMethods` (nested generics now 
preserved), `testLogAnnotation` (`@Log`'s `Level.FINE` is an 
`AttributeExpression`, now renders `Level.@FINE`).
   
   **Branch adaptations for 3.0:**
   - **Range (fix 2):** 3.0 has no left-exclusive range syntax and 
`RangeExpression` exposes only `isInclusive()`, so `visitRangeExpression` emits 
the `..<` right-exclusive form; the two left-exclusive cases from master'"'"'s 
range test are dropped.
   - **Two class copies:** the same 8 fixes are applied to both 
`groovy.console.ui.AstNodeToScriptAdapter` (exercised by the test) and the 
legacy duplicate `groovy.inspect.swingui.AstNodeToScriptAdapter`.
   - **Safe index:** 3.0 renders `VariableExpression`s with a trailing space, 
so safe-index output reads e.g. `list ?[0]` (verified to still 
re-parse/re-render as a safe index).
   
   **Tests:** `AstNodeToScriptAdapterTest` 69/69 (forced recompile+run, JDK 11).
   
   Master PR: https://github.com/apache/groovy/pull/2682
   
   ---
   🤖 Prepared with Claude Code (Opus 4.8) on behalf of @leonard84.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to