Package groovy.transform.options

# Class ImmutablePropertyHandler

java.lang.Object
groovy.transform.options.PropertyHandler
groovy.transform.options.ImmutablePropertyHandler

Direct Known Subclasses:
  `LegacyHashMapPropertyHandler`

public class ImmutablePropertyHandler extends PropertyHandler
Property handler used by immutable-style transforms.

Since:
  2.5.0

- ## Field Summary

  ### Fields inherited from class groovy.transform.options.PropertyHandler

  `PROPERTY_OPTIONS_TYPE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ImmutablePropertyHandler()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected Statement`
  `checkFinalArgNotOverridden(ClassNode cNode, FieldNode fNode)`
  Creates a statement that rejects overriding a final property value via constructor arguments.
  `protected Expression`
  `cloneCollectionExpr(Expression fieldExpr, ClassNode type)`
  Returns an immutable defensive-copy expression for the supplied collection value.
  `protected Expression`
  `createAsImmutableX(Expression expr, ClassNode type)`
  Creates an `asImmutable()` call for the supplied expression and target type.
  `protected Statement`
  `createConstructorStatement(AbstractASTTransformation xform, ClassNode cNode, PropertyNode pNode, Parameter namedArgsMap)`
  Creates the constructor statement used to initialize an immutable property.
  `Statement`
  `createPropGetter(PropertyNode pNode)`
  Create the getter block used when reading the property including any defensive copying.
  `Statement`
  `createPropInit(AbstractASTTransformation xform, AnnotationNode anno, ClassNode cNode, PropertyNode pNode, Parameter namedArgsMap)`
  Create a statement that will initialize the property including any defensive copying.
  `Statement`
  `createPropSetter(PropertyNode pNode)`
  Create the setter block used when setting the property.
  `boolean`
  `validateAttributes(AbstractASTTransformation xform, AnnotationNode anno)`
  Validates annotation attributes supported by this handler.
  `boolean`
  `validateProperties(AbstractASTTransformation xform, BlockStatement body, ClassNode cNode, List<PropertyNode> props)`
  Validates the properties selected for processing.

  ### Methods inherited from class groovy.transform.options.PropertyHandler

  `createPropertyHandler, isValidAttribute`

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

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

- ## Constructor Details

  - ### ImmutablePropertyHandler

    public ImmutablePropertyHandler()

- ## Method Details

  - ### createPropGetter

    public Statement createPropGetter(PropertyNode pNode)
    Create the getter block used when reading the property including any defensive copying.
    Overrides:
      `createPropGetter` in class `PropertyHandler`
    Parameters:
      `pNode` - the property node

  - ### createPropSetter

    public Statement createPropSetter(PropertyNode pNode)
    Create the setter block used when setting the property. Can be null for read-only properties.
    Overrides:
      `createPropSetter` in class `PropertyHandler`
    Parameters:
      `pNode` - the property node

  - ### validateAttributes

    public boolean validateAttributes(AbstractASTTransformation xform, AnnotationNode anno)
    Validates annotation attributes supported by this handler.
    Specified by:
      `validateAttributes` in class `PropertyHandler`
    Parameters:
      `xform` - the active transform
      `anno` - the property options annotation
    Returns:
      `true` if validation succeeds

  - ### validateProperties

    public boolean validateProperties(AbstractASTTransformation xform, BlockStatement body, ClassNode cNode, List<PropertyNode> props)
    Validates the properties selected for processing.
    Overrides:
      `validateProperties` in class `PropertyHandler`
    Parameters:
      `xform` - the active transform
      `body` - the statement block being generated
      `cNode` - the owning class
      `props` - the candidate properties
    Returns:
      `true` if validation succeeds

  - ### createPropInit

    public Statement createPropInit(AbstractASTTransformation xform, AnnotationNode anno, ClassNode cNode, PropertyNode pNode, Parameter namedArgsMap)
    Create a statement that will initialize the property including any defensive copying. Return `null` to indicate that no initialization statement should be emitted for this property; this is distinct from returning an empty block and skips the corresponding entry in the generated constructor body altogether.
    Specified by:
      `createPropInit` in class `PropertyHandler`
    Parameters:
      `xform` - the transform being processed
      `anno` - the annotation node
      `cNode` - the classnode containing the property
      `pNode` - the property node to initialize
      `namedArgsMap` - an "args" Map if the property value should come from a named arg map or null if not

  - ### cloneCollectionExpr

    protected Expression cloneCollectionExpr(Expression fieldExpr, ClassNode type)
    Returns an immutable defensive-copy expression for the supplied collection value.
    Parameters:
      `fieldExpr` - the original field expression
      `type` - the declared property type
    Returns:
      an expression yielding an immutable collection view

  - ### createAsImmutableX

    protected Expression createAsImmutableX(Expression expr, ClassNode type)
    Creates an `asImmutable()` call for the supplied expression and target type.
    Parameters:
      `expr` - the source expression
      `type` - the type used for the cast before invoking `asImmutable()`
    Returns:
      the immutable-conversion expression

  - ### createConstructorStatement

    protected Statement createConstructorStatement(AbstractASTTransformation xform, ClassNode cNode, PropertyNode pNode, Parameter namedArgsMap)
    Creates the constructor statement used to initialize an immutable property.
    Parameters:
      `xform` - the active transform
      `cNode` - the owning class
      `pNode` - the property being initialized
      `namedArgsMap` - the named-argument map, or `null`
    Returns:
      the initialization statement

  - ### checkFinalArgNotOverridden

    protected Statement checkFinalArgNotOverridden(ClassNode cNode, FieldNode fNode)
    Creates a statement that rejects overriding a final property value via constructor arguments.
    Parameters:
      `cNode` - the owning class
      `fNode` - the final field
    Returns:
      the generated guard statement