[
https://issues.apache.org/jira/browse/GROOVY-12015?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18081379#comment-18081379
]
ASF GitHub Bot commented on GROOVY-12015:
-----------------------------------------
sonarqubecloud[bot] commented on PR #2537:
URL: https://github.com/apache/groovy/pull/2537#issuecomment-4466582528
## [](https://sonarcloud.io/dashboard?id=apache_groovy&pullRequest=2537)
**Quality Gate passed**
Issues
 [0 New
issues](https://sonarcloud.io/project/issues?id=apache_groovy&pullRequest=2537&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted
issues](https://sonarcloud.io/project/issues?id=apache_groovy&pullRequest=2537&issueStatuses=ACCEPTED)
Measures
 [0 Security
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_groovy&pullRequest=2537&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New
Code](https://sonarcloud.io/component_measures?id=apache_groovy&pullRequest=2537&metric=new_coverage&view=list)
 [0.0% Duplication on New
Code](https://sonarcloud.io/component_measures?id=apache_groovy&pullRequest=2537&metric=new_duplicated_lines_density&view=list)
<!
> Provide a nested copyWith capability
> ------------------------------------
>
> Key: GROOVY-12015
> URL: https://issues.apache.org/jira/browse/GROOVY-12015
> Project: Groovy
> Issue Type: New Feature
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
> h3. Summary
> Extends {{copyWith}} (generated for {{@Immutable}} and {{@RecordType}}
> classes declared with {{{}copyWith=true{}}}) with nested-path support and a
> transactional block form, for ergonomic updates of immutable object graphs.
> h3. Nested-path map form
> A {{copyWith}} key may now be a dotted path; the affected nested nodes are
> rebuilt recursively and untouched branches are reused.
> {code:groovy}
> def q = p.copyWith('address.city': 'NYC', 'address.zip': '10001')
> {code}
> * Works for arbitrarily deep paths and heterogeneous {{{}@Immutable{}}}/
> {{@RecordType}} graphs (record-in-record included).
> * Plain (non-dotted) keys behave exactly as before.
> * Identity is preserved transitively: if nothing changes, the original
> instance is returned.
> * Every node on a nested path must itself provide {{{}copyWith(Map){}}};
> otherwise a clear, specific error is raised.
> h3. Transactional block form
> A {{copyWith(Closure)}} overload is also generated:
> {code:groovy}
> def q = p.copyWith {
> name = 'Bob' // plain set
> address.city = old.address.city.reverse() // derive from the original
> fullName = old.first + ' ' + old.last // cross-field derivation
> loginCount.modify { it + 1 } // single-field shorthand
> }
> {code}
> * {{old}} resolves to the original (pre-state) object, consistent with
> {{old}} in {{{}@Ensures{}}}/{{{}@Contract{}}}, and may be used to derive any
> new
> value, including across fields.
> * {{prop.modify\{ \} }} is a shorthand for the common
> transform-this-same-field case.
> * To invoke a real same-named {{modify}} method on a value type (or simply
> for readability), use the {{old}} form: x = old.x.modify { ... \}.
> * An empty or no-op block returns the original instance.
> h3. Compatibility
> * A no-arg {{copyWith()}} is generated, returning the same instance
> (preserving the historical zero-argument behaviour).
> * Existing single-level and Map-based {{copyWith}} usage is unchanged.
> * Shared generation logic is used by both the {{@Immutable}} and
> {{@RecordType}} transforms so behaviour stays identical across the two.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)