Class CopyWithRecorder

java.lang.Object
groovy.lang.GroovyObjectSupport
org.apache.groovy.transform.copywith.CopyWithRecorder
All Implemented Interfaces:
GroovyObject

@Incubating public class CopyWithRecorder extends GroovyObjectSupport
Recording delegate for the transactional copyWith { } block. It does not mutate anything: property assignments and prop.modify { } calls are recorded as a (possibly dotted) path-keyed map which is then handed to the nested-aware copyWith(Map) for reconstruction.

Reads of a property return a child recorder bound to the extended path, so address.city = 'NYC' records 'address.city'.

The reserved name old resolves to the original (root) object — aligning with the old of @Ensures/@Contract in design-by-contract — so a value may be derived from the pre-state: address.city = old.address.city.reverse() or, cross-field, name = old.company.name. The concise single-field shorthand address.city.modify { it.reverse() } remains for the common transform-this-same-field case.

On a navigated path the recorder intercepts modify, so a same-named real method on the value type is shadowed there. old is the escape hatch: past old the RHS is the real object, so a genuine modify(Closure) (or any other domain method) runs and its result is recorded — e.g. balance = old.balance.modify { it + 50 }. old may equally be preferred purely for style, when .modify on a path could be misread, even if no real method exists.

Since:
6.0.0
  • Constructor Details

  • Method Details

    • getProperty

      public Object getProperty(String name)
      Description copied from interface: GroovyObject
      Retrieves a property value.
      Parameters:
      name - the name of the property of interest
      Returns:
      the given property
    • setProperty

      public void setProperty(String name, Object value)
      Description copied from interface: GroovyObject
      Sets the given property to the new value.
      Parameters:
      name - the name of the property of interest
      value - the new value for the property
    • invokeMethod

      public Object invokeMethod(String name, Object args)
      Description copied from interface: GroovyObject
      Invokes the given method.
      Parameters:
      name - the name of the method to call
      args - the arguments to use for the method call
      Returns:
      the result of invoking the method