Skip to content

GROOVY-11893: Standardise hooks for Groovy pretty printing#2424

Merged
paulk-asert merged 1 commit intoapache:masterfrom
paulk-asert:groovy11893
Apr 13, 2026
Merged

GROOVY-11893: Standardise hooks for Groovy pretty printing#2424
paulk-asert merged 1 commit intoapache:masterfrom
paulk-asert:groovy11893

Conversation

@paulk-asert
Copy link
Copy Markdown
Contributor

No description provided.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 62.31884% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.4994%. Comparing base (684f190) to head (5e35df0).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...java/org/codehaus/groovy/runtime/FormatHelper.java 61.3636% 9 Missing and 8 partials ⚠️
.../codehaus/groovy/runtime/DefaultGroovyMethods.java 37.5000% 5 Missing ⚠️
...roovy/lang/IncorrectClosureArgumentsException.java 0.0000% 2 Missing ⚠️
src/main/java/groovy/lang/MetaMethod.java 33.3333% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                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     
Files with missing lines Coverage Δ
src/main/java/groovy/lang/MetaClassImpl.java 76.9616% <100.0000%> (ø)
.../codehaus/groovy/reflection/CachedConstructor.java 54.3478% <100.0000%> (ø)
...rg/codehaus/groovy/runtime/ArrayGroovyMethods.java 89.7139% <100.0000%> (+0.0567%) ⬆️
...roovy/lang/IncorrectClosureArgumentsException.java 0.0000% <0.0000%> (ø)
src/main/java/groovy/lang/MetaMethod.java 50.0000% <33.3333%> (ø)
.../codehaus/groovy/runtime/DefaultGroovyMethods.java 74.7030% <37.5000%> (-0.0864%) ⬇️
...java/org/codehaus/groovy/runtime/FormatHelper.java 78.6026% <61.3636%> (+0.4776%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 FormatHelper to prefer groovyToString() (via the metaclass) when doing default formatting, plus aligns write/append behavior.
  • 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.

@paulk-asert paulk-asert merged commit 165bfd1 into apache:master Apr 13, 2026
22 checks passed
@paulk-asert paulk-asert deleted the groovy11893 branch April 13, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants