Skip to content

GROOVY-12015: Provide a nested copyWith capability#2537

Merged
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy12015
May 18, 2026
Merged

GROOVY-12015: Provide a nested copyWith capability#2537
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy12015

Conversation

@paulk-asert
Copy link
Copy Markdown
Contributor

@paulk-asert paulk-asert commented May 16, 2026

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

Adds nested-path support to copyWith(Map) (e.g. 'address.city') and introduces a transactional copyWith { ... } block form for @Immutable(copyWith=true) and @RecordType(copyWith=true), backed by shared runtime/AST utilities.

Changes:

  • Introduces runtime support (NestedCopyWithSupport, CopyWithRecorder) and shared AST generation helpers (CopyWithUtils).
  • Updates @Immutable and @RecordType AST transforms to flatten nested keys and generate a copyWith(Closure) overload (and for @Immutable, a copyWith() identity shim).
  • Adds new JUnit tests covering nested map updates and the transactional block form; updates annotation docs.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/test/groovy/org/codehaus/groovy/transform/RecordNestedCopyWithTest.groovy Adds tests for nested copyWith and block form on @RecordType(copyWith=true).
src/test/groovy/org/codehaus/groovy/transform/ImmutableNestedCopyWithTest.groovy Adds comprehensive tests for nested copyWith and block form on @Immutable(copyWith=true).
src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java Makes record copyWith(Map) nested-aware and adds the block overload.
src/main/java/org/codehaus/groovy/transform/RecordCompletionASTTransformation.java Adjusts record completion logic to handle the new block-wrapped copyWith body.
src/main/java/org/codehaus/groovy/transform/ImmutableASTTransformation.java Makes immutable copyWith(Map) nested-aware and adds identity/block overloads.
src/main/java/org/apache/groovy/transform/copywith/NestedCopyWithSupport.java Implements runtime flattening of dotted keys and applies the block form.
src/main/java/org/apache/groovy/transform/copywith/CopyWithRecorder.java Implements the recording delegate for copyWith { ... }.
src/main/java/org/apache/groovy/ast/tools/CopyWithUtils.java Adds shared AST helpers for emitting nested flattening and overload methods.
src/main/java/groovy/transform/RecordOptions.java Documents nested-path and block-form copyWith for records.
src/main/java/groovy/transform/ImmutableBase.java Documents nested-path and block-form copyWith for immutables.

Comment thread src/main/java/org/codehaus/groovy/transform/RecordTypeASTTransformation.java Outdated
@paulk-asert paulk-asert force-pushed the groovy12015 branch 2 times, most recently from 8e112ee to 4139177 Compare May 17, 2026 12:02
@sonarqubecloud
Copy link
Copy Markdown

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.17204% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.1861%. Comparing base (1b70ef4) to head (b187567).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...oovy/transform/copywith/NestedCopyWithSupport.java 87.1795% 1 Missing and 4 partials ⚠️
...he/groovy/transform/copywith/CopyWithRecorder.java 80.0000% 1 Missing and 3 partials ⚠️
...ava/org/apache/groovy/ast/tools/CopyWithUtils.java 93.3333% 0 Missing and 1 partial ⚠️
...y/transform/RecordCompletionASTTransformation.java 50.0000% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2537        +/-   ##
==================================================
+ Coverage     68.1651%   68.1861%   +0.0209%     
- Complexity      32860      32888        +28     
==================================================
  Files            1499       1502         +3     
  Lines          125394     125486        +92     
  Branches        22665      22680        +15     
==================================================
+ Hits            85475      85564        +89     
+ Misses          32399      32398         -1     
- Partials         7520       7524         +4     
Files with missing lines Coverage Δ
...s/groovy/transform/ImmutableASTTransformation.java 67.3367% <100.0000%> (+0.4999%) ⬆️
.../groovy/transform/RecordTypeASTTransformation.java 84.7973% <100.0000%> (+0.6984%) ⬆️
...ava/org/apache/groovy/ast/tools/CopyWithUtils.java 93.3333% <93.3333%> (ø)
...y/transform/RecordCompletionASTTransformation.java 78.5714% <50.0000%> (-2.1978%) ⬇️
...he/groovy/transform/copywith/CopyWithRecorder.java 80.0000% <80.0000%> (ø)
...oovy/transform/copywith/NestedCopyWithSupport.java 87.1795% <87.1795%> (ø)

... and 7 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.

@testlens-app
Copy link
Copy Markdown

testlens-app Bot commented May 18, 2026

✅ All tests passed ✅

🏷️ Commit: b187567
▶️ Tests: 70338 executed
⚪️ Checks: 28/28 completed


Learn more about TestLens at testlens.app.

@paulk-asert paulk-asert merged commit aaec60c into apache:master May 18, 2026
29 checks passed
@paulk-asert paulk-asert deleted the groovy12015 branch May 18, 2026 23:45
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