Package groovy.transform.options
Class PropertyHandler
java.lang.Object
groovy.transform.options.PropertyHandler
- Direct Known Subclasses:
DefaultPropertyHandler,ImmutablePropertyHandler
Used to provide custom property handling when getting, setting or initializing properties.
- Since:
- 2.5.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PropertyHandlercreatePropertyHandler(AbstractASTTransformation xform, GroovyClassLoader loader, ClassNode cNode) Creates the property handler configured for the supplied class.createPropGetter(PropertyNode pNode) Create the getter block used when reading the property including any defensive copying.abstract StatementcreatePropInit(AbstractASTTransformation xform, AnnotationNode anno, ClassNode cNode, PropertyNode pNode, Parameter namedArgMap) Create a statement that will initialize the property including any defensive copying.createPropSetter(PropertyNode pNode) Create the setter block used when setting the property.protected booleanisValidAttribute(AbstractASTTransformation xform, AnnotationNode anno, String memberName) Checks whether the named annotation attribute is unsupported for this handler.abstract 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.
-
Field Details
-
PROPERTY_OPTIONS_TYPE
Class node forPropertyOptions.
-
-
Constructor Details
-
PropertyHandler
public PropertyHandler()
-
-
Method Details
-
validateAttributes
Validates annotation attributes supported by this handler.- 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.- Parameters:
xform- the active transformbody- the statement block being generatedcNode- the owning classprops- the candidate properties- Returns:
trueif validation succeeds
-
createPropInit
public abstract Statement createPropInit(AbstractASTTransformation xform, AnnotationNode anno, ClassNode cNode, PropertyNode pNode, Parameter namedArgMap) Create a statement that will initialize the property including any defensive copying. Null if no statement should be added.- Parameters:
xform- the transform being processedanno- the '@ImmutableBase' annotation nodecNode- the classnode containing the propertypNode- the property node to initializenamedArgMap- an "args" Map if the property value should come from a named arg map or null if not
-
createPropGetter
Create the getter block used when reading the property including any defensive copying.- Parameters:
pNode- the property node
-
createPropSetter
Create the setter block used when setting the property. Can be null for read-only properties.- Parameters:
pNode- the property node
-
isValidAttribute
protected boolean isValidAttribute(AbstractASTTransformation xform, AnnotationNode anno, String memberName) Checks whether the named annotation attribute is unsupported for this handler.- Parameters:
xform- the active transformanno- the annotation being processedmemberName- the attribute name to validate- Returns:
trueif the attribute is valid for this handler
-
createPropertyHandler
public static PropertyHandler createPropertyHandler(AbstractASTTransformation xform, GroovyClassLoader loader, ClassNode cNode) Creates the property handler configured for the supplied class.- Parameters:
xform- the active transformloader- the class loader used to instantiate custom handlerscNode- the class being transformed- Returns:
- the configured property handler, or
nullif one could not be created
-