GROOVY-12144: Fix AstNodeToScriptAdapter decompiler rendering fidelity (GROOVY_3_0_X backport)#2686
Merged
paulk-asert merged 1 commit intoJul 11, 2026
Conversation
GROOVY_3_0_X backport of master commit 4b27025. Applies the eight visitor fixes (nested generics, range bounds, elvis, attribute access, explicit closure arrow, safe index access, numeric literal suffixes, explicit method type arguments) to both copies of the class on this branch: groovy.console.ui.AstNodeToScriptAdapter (exercised by the test) and the legacy duplicate groovy.inspect.swingui.AstNodeToScriptAdapter. Adaptations for 3.0: - Range fix uses RangeExpression.isInclusive() and emits the `..<` right-exclusive form; 3.0 has no left-exclusive range syntax, so the two left-exclusive cases from master's range test are dropped. - Safe index access renders `?[`; 3.0 renders VariableExpressions with a trailing space, so output reads e.g. `list ?[0]` (verified to still re-parse and re-render as a safe index). Adds one regression test per defect (GroovyTestCase style). Reconciles existing tests to the branch's corrected output: testTernaryOperaters (elvis), testGenericsInMethods (nested generics now preserved), testLogAnnotation (@log's Level.FINE AttributeExpression now renders .@fine). Assisted-by: Claude Code (Opus 4.8)
Contributor
|
We aren't necessarily planning another 3.x release but I guess no harm in having this in place of we do. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This backports the eight decompiler-fidelity fixes from master (#2682, commit
4b27025962) toGROOVY_3_0_X.AstNodeToScriptVisitorrendered several constructs so they did not round-trip; each fix is localized to one visitor method:Map<String, List<Integer>>→Map<String, List>) —visitGenericsrecurses into concrete args.visitRangeExpression.c ?: d→c ? c : d, evaluatingctwice) —visitShortTernaryExpressionemits?:.obj.@f→obj.f) —visitPropertyExpressionemits.@for anAttributeExpression.{ -> ... }→{ ... }) —visitClosureExpressiondistinguishes a null parameter list fromParameter.EMPTY_ARRAY.list?[0]→list[0]) —visitBinaryExpression.42L/2.5f/3.5d/10G) —visitConstantExpressionre-appendsL/F/D/G.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'sLevel.FINEis anAttributeExpression, now rendersLevel.@FINE).Branch adaptations for 3.0:
RangeExpressionexposes onlyisInclusive(), sovisitRangeExpressionemits the..<right-exclusive form; the two left-exclusive cases from master'"'"'s range test are dropped.groovy.console.ui.AstNodeToScriptAdapter(exercised by the test) and the legacy duplicategroovy.inspect.swingui.AstNodeToScriptAdapter.VariableExpressions 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:
AstNodeToScriptAdapterTest69/69 (forced recompile+run, JDK 11).Master PR: #2682
🤖 Prepared with Claude Code (Opus 4.8) on behalf of @leonard84.