GROOVY-11893: Standardise hooks for Groovy pretty printing#2424
Merged
paulk-asert merged 1 commit intoapache:masterfrom Apr 13, 2026
Merged
GROOVY-11893: Standardise hooks for Groovy pretty printing#2424paulk-asert merged 1 commit intoapache:masterfrom
paulk-asert merged 1 commit intoapache:masterfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2424 +/- ##
==================================================
- Coverage 66.5016% 66.4994% -0.0022%
- Complexity 30399 30416 +17
==================================================
Files 1420 1420
Lines 118555 118577 +22
Branches 21042 21044 +2
==================================================
+ Hits 78841 78853 +12
- Misses 33200 33204 +4
- Partials 6514 6520 +6
🚀 New features to boost your workflow:
|
592165b to
cb0f31f
Compare
3677041 to
35d85e1
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a standardized groovyToString() hook for Groovy’s “pretty printing” pipeline, letting core formatting (e.g., interpolation/println/assert messages) consistently route through overridable extension methods.
Changes:
- Adds
groovyToString(...)extension methods for core container-ish types (Map, Collection, Range, arrays, XML Element). - Updates
FormatHelperto prefergroovyToString()(via the metaclass) when doing default formatting, plus alignswrite/appendbehavior. - Updates a macro library test expectation and refines several internal error-message renderings to use
toArrayString(...).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| subprojects/groovy-macro-library/src/test/groovy/org/apache/groovy/macrolib/MacroLibTest.groovy | Updates expected SV(...).toString() output for ranges to use 0..5 representation. |
| src/main/java/org/codehaus/groovy/runtime/FormatHelper.java | Adds metaclass-based groovyToString() lookup and routes default formatting/write/append through it. |
| src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | Introduces groovyToString for Map/Range/Collection/XML Element as the default formatting hook. |
| src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java | Introduces groovyToString overloads for Object[] and primitive arrays. |
| src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java | Switches argument rendering in exception message to FormatHelper.toArrayString(...). |
| src/main/java/groovy/lang/MetaMethod.java | Uses toArrayString(...) for parameter/argument array rendering in error text and toString(). |
| src/main/java/groovy/lang/MetaClassImpl.java | Uses toArrayString(...) when building ambiguity error messages. |
| src/main/java/groovy/lang/IncorrectClosureArgumentsException.java | Uses toArrayString(...) for expected signature formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f2c892c to
5e35df0
Compare
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.
No description provided.