Package groovy.transform.options
Class ImmutablePropertyHandler
java.lang.Object
groovy.transform.options.PropertyHandler
groovy.transform.options.ImmutablePropertyHandler
- Direct Known Subclasses:
LegacyHashMapPropertyHandler
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected StatementcheckFinalArgNotOverridden(ClassNode cNode, FieldNode fNode) Creates a statement that rejects overriding a final property value via constructor arguments.protected ExpressioncloneCollectionExpr(Expression fieldExpr, ClassNode type) Returns an immutable defensive-copy expression for the supplied collection value.protected ExpressioncreateAsImmutableX(Expression expr, ClassNode type) Creates anasImmutable()call for the supplied expression and target type.protected StatementcreateConstructorStatement(AbstractASTTransformation xform, ClassNode cNode, PropertyNode pNode, Parameter namedArgsMap) Creates the constructor statement used to initialize an immutable property.createPropGetter(PropertyNode pNode) Create the getter block used when reading the property including any defensive copying.createPropInit(AbstractASTTransformation xform, AnnotationNode anno, ClassNode cNode, PropertyNode pNode, Parameter namedArgsMap) Create a statement that will initialize the property including any defensive copying.createPropSetter(PropertyNode pNode) Create the setter block used when setting the property.booleanvalidateAttributes(AbstractASTTransformation xform, AnnotationNode anno) Validates annotation attributes supported by this handler.booleanvalidateProperties(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
-
Constructor Details
-
ImmutablePropertyHandler
public ImmutablePropertyHandler()
-
-
Method Details
-
createPropGetter
Create the getter block used when reading the property including any defensive copying.- Overrides:
createPropGetterin classPropertyHandler- Parameters:
pNode- the property node
-
createPropSetter
Create the setter block used when setting the property. Can be null for read-only properties.- Overrides:
createPropSetterin classPropertyHandler- Parameters:
pNode- the property node
-
validateAttributes
Validates annotation attributes supported by this handler.- Specified by:
validateAttributesin classPropertyHandler- Parameters:
xform- the active transformanno- the property options annotation- Returns:
trueif validation succeeds
-
validateProperties
public boolean validateProperties(AbstractASTTransformation xform, BlockStatement body, ClassNode cNode, List<PropertyNode> props) Validates the properties selected for processing.- Overrides:
validatePropertiesin classPropertyHandler- Parameters:
xform- the active transformbody- the statement block being generatedcNode- the owning classprops- the candidate properties- Returns:
trueif 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. Null if no statement should be added.- Specified by:
createPropInitin classPropertyHandler- Parameters:
xform- the transform being processedanno- the '@ImmutableBase' annotation nodecNode- the classnode containing the propertypNode- the property node to initializenamedArgsMap- an "args" Map if the property value should come from a named arg map or null if not
-
cloneCollectionExpr
Returns an immutable defensive-copy expression for the supplied collection value.- Parameters:
fieldExpr- the original field expressiontype- the declared property type- Returns:
- an expression yielding an immutable collection view
-
createAsImmutableX
Creates anasImmutable()call for the supplied expression and target type.- Parameters:
expr- the source expressiontype- the type used for the cast before invokingasImmutable()- 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 transformcNode- the owning classpNode- the property being initializednamedArgsMap- the named-argument map, ornull- Returns:
- the initialization statement
-
checkFinalArgNotOverridden
Creates a statement that rejects overriding a final property value via constructor arguments.- Parameters:
cNode- the owning classfNode- the final field- Returns:
- the generated guard statement
-