Package org.apache.groovy.ast.tools

# Class CopyWithUtils

java.lang.Object
org.apache.groovy.ast.tools.CopyWithUtils

public final class CopyWithUtils extends Object
Shared AST-generation glue for nested-path `copyWith`, used by both the `@Immutable` and `@RecordType` transforms so the generated code (and its evolution) stays identical across the two.

Since:
  6.0.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `addCopyWithBlockMethod(ClassNode cNode)`
  The transactional block overload: `copyWith { name = 'x'; address.city = 'y' }`.
  `static void`
  `addCopyWithIdentityMethod(ClassNode cNode)`
  Backward-compatibility shim: a no-arg `copyWith()` with its historical semantics (no changes → the same instance).
  `static Statement`
  `nestedFlattenStmt(String mapParamName)`
  The leading statement of a nested-aware `copyWith(Map)`: `<mapParamName> = NestedCopyWithSupport.flatten(this, <mapParamName>)`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### nestedFlattenStmt

    public static Statement nestedFlattenStmt(String mapParamName)
    The leading statement of a nested-aware `copyWith(Map)`: `<mapParamName> = NestedCopyWithSupport.flatten(this, <mapParamName>)`. Plain keys pass through unchanged, so flat usage is unaffected.

  - ### addCopyWithIdentityMethod

    public static void addCopyWithIdentityMethod(ClassNode cNode)
    Backward-compatibility shim: a no-arg `copyWith()` with its historical semantics (no changes → the same instance). Needed once a `copyWith(Closure)` overload exists, otherwise the historically supported zero-arg call becomes ambiguous.

  - ### addCopyWithBlockMethod

    public static void addCopyWithBlockMethod(ClassNode cNode)
    The transactional block overload: `copyWith { name = 'x'; address.city = 'y' }`.