GROOVY-12015: Provide a nested copyWith capability#2537
Conversation
There was a problem hiding this comment.
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
@Immutableand@RecordTypeAST transforms to flatten nested keys and generate acopyWith(Closure)overload (and for@Immutable, acopyWith()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. |
8e112ee to
4139177
Compare
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: b187567 Learn more about TestLens at testlens.app. |



https://issues.apache.org/jira/browse/GROOVY-12015