Package: groovy.transform.options

## [Java] Class ImmutablePropertyHandler

- groovy.transform.options.ImmutablePropertyHandler

-     public class ImmutablePropertyHandler
      extends PropertyHandler

  Property handler used by immutable-style transforms.

  Since:
    2.5.0

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class PropertyHandler` | `PROPERTY_OPTIONS_TYPE`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and 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.
    `` | `public Statement` | `createPropGetter(PropertyNode pNode)` Create the getter block used when reading the property including any defensive copying. Parameters: `pNode` - the property node
    `` | `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. Null if no statement should be added. Parameters: `xform` - the transform being processed `anno` - the '@ImmutableBase' annotation node `cNode` - the classnode containing the property `pNode` - the property node to initialize `namedArgMap` - an "args" Map if the property value should come from a named arg map or null if not
    `` | `public Statement` | `createPropSetter(PropertyNode pNode)` Create the setter block used when setting the property. Can be null for read-only properties. Parameters: `pNode` - the property node
    `` | `public boolean` | `validateAttributes(AbstractASTTransformation xform, AnnotationNode anno)` Validates annotation attributes supported by this handler. Parameters: `xform` - the active transform `anno` - the property options annotation Returns: `true` if validation succeeds
    `` | `public boolean` | `validateProperties(AbstractASTTransformation xform, BlockStatement body, ClassNode cNode, List<PropertyNode> props)` Validates the properties selected for processing. Parameters: `xform` - the active transform `body` - the statement block being generated `cNode` - the owning class `props` - the candidate properties Returns: `true` if validation succeeds

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class PropertyHandler` | `createPropGetter, createPropInit, createPropSetter, createPropertyHandler, isValidAttribute, validateAttributes, validateProperties`

- - ### Method Detail

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### public Statement createPropGetter(PropertyNode pNode)

      Create the getter block used when reading the property including any defensive copying.

      Parameters:
        `pNode` - the property node

    - #### 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. Null if no statement should be added.

      Parameters:
        `xform` - the transform being processed
        `anno` - the '@ImmutableBase' annotation node
        `cNode` - the classnode containing the property
        `pNode` - the property node to initialize
        `namedArgMap` - an "args" Map if the property value should come from a named arg map or null if not

    - #### public Statement createPropSetter(PropertyNode pNode)

      Create the setter block used when setting the property. Can be null for read-only properties.

      Parameters:
        `pNode` - the property node

    - #### public boolean validateAttributes(AbstractASTTransformation xform, AnnotationNode anno)

      Validates annotation attributes supported by this handler.

      Parameters:
        `xform` - the active transform
        `anno` - the property options annotation
      Returns:
        `true` if validation succeeds

    - #### public boolean validateProperties(AbstractASTTransformation xform, BlockStatement body, ClassNode cNode, List<PropertyNode> props)

      Validates the properties selected for processing.

      Parameters:
        `xform` - the active transform
        `body` - the statement block being generated
        `cNode` - the owning class
        `props` - the candidate properties
      Returns:
        `true` if validation succeeds