Top Description Fields Constructors Methods
groovy.beans

public Class VetoableASTTransformation

extends BindableASTTransformation
Class Inheritance
Annotations
@GroovyASTTransformation
phase:CANONICALIZATION
Imports
org.codehaus.groovy.ast.ASTNode, .AnnotatedNode, .AnnotationNode, .ClassHelper, .ClassNode, .FieldNode, .MethodNode, .Parameter, .PropertyNode, org.codehaus.groovy.ast.expr.Expression, org.codehaus.groovy.ast.stmt.BlockStatement, .Statement, org.codehaus.groovy.ast.tools.PropertyNodeUtils, org.codehaus.groovy.control.CompilePhase, .SourceUnit, org.codehaus.groovy.control.messages.SimpleMessage, org.codehaus.groovy.transform.GroovyASTTransformation, org.objectweb.asm.Opcodes, java.beans.PropertyVetoException, .VetoableChangeListener, .VetoableChangeSupport

Handles generation of code for the @Vetoable annotation, and @Bindable if also present.

Generally, it adds (if needed) a VetoableChangeSupport field and the needed add/removeVetoableChangeListener methods to support the listeners.

It also generates the setter and wires the setter through the VetoableChangeSupport.

If a Bindable annotation is detected it also adds support similar to what BindableASTTransformation would do.

Field Summary

Modifier and TypeField and Description
protected static final ClassNode
Inherited from groovy.beans.BindableASTTransformation:
boundClassNode

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private void
protected void
addVetoableChangeSupport(ClassNode
the class to which we add the support field and methods
declaringClass
)

Adds the necessary field and methods to support vetoable change support.

protected Statement

Returns:

the created statement
createConstrainedStatement
(PropertyNode
the field node for the property
propertyNode
,
Expression
a field expression for setting the property value
fieldExpression
)

Creates a statement body similar to: this.fireVetoableChange("field", field, field = value)

private void
createListenerSetter(SourceUnit source, boolean bindable, ClassNode declaringClass, PropertyNode propertyNode)

protected Statement

Returns:

the created statement
createSetStatement
(Expression
a field expression for setting the property value
fieldExpression
)

Creates a statement body similar to: field = value.

protected void
createSetterMethod(ClassNode
the class to which we will add the setter
declaringClass
,
PropertyNode
the field to back the setter
propertyNode
,
String
the name of the setter
setterName
,
Statement
the statement representing the setter block
setterBlock
)

Overrides groovy.beans.BindableASTTransformation.createSetterMethod.

Creates a setter method with the given body.
public static boolean

Returns:

true if the node is constrained
hasVetoableAnnotation
(AnnotatedNode
the node to check
node
)

Convenience method to see if an annotated node is @Vetoable.

protected boolean

Returns:

true if vetoable change support should be added
needsVetoableChangeSupport
(ClassNode
the class to search
declaringClass
,
SourceUnit sourceUnit)

Snoops through the declaring class and all parents looking for a field of type VetoableChangeSupport.

public void
visit(ASTNode[]
the AST nodes
nodes
,
SourceUnit
the source unit for the nodes
source
)

Overrides groovy.beans.BindableASTTransformation.visit.

Implements org.codehaus.groovy.transform.ASTTransformation.visit.

Handles the bulk of the processing, mostly delegating to other methods.
private static void
wrapSetterMethod(ClassNode classNode, boolean bindable, String propertyName)

Wrap an existing setter.

Inherited from groovy.beans.BindableASTTransformation:
addPropertyChangeSupportcreateBindableStatementhasBindableAnnotationneedsPropertyChangeSupport

Field Detail

constrainedClassNodeback to summary
protected static final ClassNode constrainedClassNode

Constructor Detail

VetoableASTTransformationback to summary
public VetoableASTTransformation()

Method Detail

addListenerToClassback to summary
private void addListenerToClass(SourceUnit source, ClassNode classNode)

Hides groovy.beans.BindableASTTransformation.addListenerToClass.

addListenerToPropertyback to summary
private void addListenerToProperty(SourceUnit source, AnnotationNode node, AnnotatedNode parent)
addVetoableChangeSupportback to summary
protected void addVetoableChangeSupport(ClassNode declaringClass)

Adds the necessary field and methods to support vetoable change support.

Adds a new field: "protected final java.beans.VetoableChangeSupport this$vetoableChangeSupport = new java.beans.VetoableChangeSupport(this)"

Also adds support methods: public void addVetoableChangeListener(java.beans.VetoableChangeListener) public void addVetoableChangeListener(String, java.beans.VetoableChangeListener) public void removeVetoableChangeListener(java.beans.VetoableChangeListener) public void removeVetoableChangeListener(String, java.beans.VetoableChangeListener) public java.beans.VetoableChangeListener[] getVetoableChangeListeners()

Parameters
declaringClass:ClassNode

the class to which we add the support field and methods

createConstrainedStatementback to summary
protected Statement createConstrainedStatement(PropertyNode propertyNode, Expression fieldExpression)

Creates a statement body similar to: this.fireVetoableChange("field", field, field = value)

Parameters
propertyNode:PropertyNode

the field node for the property

fieldExpression:Expression

a field expression for setting the property value

Returns:Statement

the created statement

createListenerSetterback to summary
private void createListenerSetter(SourceUnit source, boolean bindable, ClassNode declaringClass, PropertyNode propertyNode)
createSetStatementback to summary
protected Statement createSetStatement(Expression fieldExpression)

Creates a statement body similar to: field = value.

Used when the field is not also @Bindable.

Parameters
fieldExpression:Expression

a field expression for setting the property value

Returns:Statement

the created statement

createSetterMethodback to summary
protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock)

Overrides groovy.beans.BindableASTTransformation.createSetterMethod.

Creates a setter method with the given body.

This differs from normal setters in that we need to add a declared exception java.beans.PropertyVetoException

Parameters
declaringClass:ClassNode

the class to which we will add the setter

propertyNode:PropertyNode

the field to back the setter

setterName:String

the name of the setter

setterBlock:Statement

the statement representing the setter block

hasVetoableAnnotationback to summary
public static boolean hasVetoableAnnotation(AnnotatedNode node)

Convenience method to see if an annotated node is @Vetoable.

Parameters
node:AnnotatedNode

the node to check

Returns:boolean

true if the node is constrained

needsVetoableChangeSupportback to summary
protected boolean needsVetoableChangeSupport(ClassNode declaringClass, SourceUnit sourceUnit)

Snoops through the declaring class and all parents looking for a field of type VetoableChangeSupport. Remembers the field and returns false if found otherwise returns true to indicate that such support should be added.

Parameters
declaringClass:ClassNode

the class to search

Returns:boolean

true if vetoable change support should be added

visitback to summary
public void visit(ASTNode[] nodes, SourceUnit source)

Overrides groovy.beans.BindableASTTransformation.visit.

Implements org.codehaus.groovy.transform.ASTTransformation.visit.

Handles the bulk of the processing, mostly delegating to other methods.

Parameters
nodes:ASTNode[]

the AST nodes

source:SourceUnit

the source unit for the nodes

wrapSetterMethodback to summary
private static void wrapSetterMethod(ClassNode classNode, boolean bindable, String propertyName)

Wrap an existing setter.