Class NestedCopyWithSupport

java.lang.Object
org.apache.groovy.transform.copywith.NestedCopyWithSupport

@Incubating @GroovyABI(since="6.0.0") public final class NestedCopyWithSupport extends Object
Runtime support for nested-path copyWith. Resolves dotted keys such as 'address.city' into a flat map of top-level property to its replacement value, by recursively applying copyWith to the affected nested nodes. Plain (non-dotted) keys pass through unchanged.

A nested node whose type does not provide copyWith(Map) fails with a clear, specific error rather than silent or partial behaviour. Identity is preserved transitively: an unchanged nested node yields its original reference, so an unchanged graph yields the original root.

Since:
6.0.0
  • Method Details

    • applyBlock

      public static Object applyBlock(Object self, Closure<?> block)
      Transactional-block form. Runs block against a recording delegate that captures plain assignments, nested-path navigation, and prop.modify { old -> ... } updates, then delegates to the (nested-aware) copyWith(Map). The block is thus pure sugar over the map form, inheriting its closed-type-domain and identity guarantees.
    • flatten

      public static Map<Object,Object> flatten(Object self, Map<Object,Object> raw)
      Flattens dotted copyWith keys against self. A null raw map yields an empty map. A key with no dot is copied through. A key head.rest is grouped under head, and the current value of that property is replaced by calling copyWith on it with the remaining entries. Using one name both as a whole value and as a dotted path is rejected. A null nested value, a Class value, or a value that does not answer copyWith(Map) is rejected as well.
      Parameters:
      self - object whose nested properties are copied
      raw - plain and dotted keys supplied to copyWith
      Returns:
      a map whose keys are top-level property names