Top Description Fields Constructors Methods
groovy.beans

public Class BindableASTTransformation

extends Object
implements ASTTransformation, Opcodes
Class Inheritance
All Implemented Interfaces
org.objectweb.asm.Opcodes, org.codehaus.groovy.transform.ASTTransformation
Known Direct Subclasses
groovy.beans.VetoableASTTransformation
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.ASTTransformation, .GroovyASTTransformation, org.objectweb.asm.Opcodes, java.beans.PropertyChangeListener, .PropertyChangeSupport

Handles generation of code for the @Bindable annotation when @Vetoable is not present.

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

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

If a Vetoable annotation is detected it does nothing and lets the VetoableASTTransformation handle all the changes.

Field Summary

Modifier and TypeField and Description
protected static final ClassNode

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private void
addListenerToProperty(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field)

protected void
addPropertyChangeSupport(ClassNode
the class to which we add the support field and methods
declaringClass
)

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

protected Statement

Returns:

the created statement
createBindableStatement
(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.firePropertyChange("field", field, field = value)

private void
createListenerSetter(ClassNode classNode, PropertyNode propertyNode)

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
)

Creates a setter method with the given body.

public static boolean

Returns:

true if the node is bindable
hasBindableAnnotation
(AnnotatedNode
the node to check
node
)

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

protected boolean

Returns:

true if property change support should be added
needsPropertyChangeSupport
(ClassNode
the class to search
declaringClass
,
SourceUnit
the source unit, for error reporting. @NotNull.
sourceUnit
)

Snoops through the declaring class and all parents looking for methods void addPropertyChangeListener(PropertyChangeListener), void removePropertyChangeListener(PropertyChangeListener), and void firePropertyChange(String, Object, Object).

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

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

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

boundClassNodeback to summary
protected static final ClassNode boundClassNode

Constructor Detail

BindableASTTransformationback to summary
public BindableASTTransformation()

Method Detail

addListenerToClassback to summary
private void addListenerToClass(SourceUnit source, ClassNode classNode)
addListenerToPropertyback to summary
private void addListenerToProperty(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field)
addPropertyChangeSupportback to summary
protected void addPropertyChangeSupport(ClassNode declaringClass)

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

Adds a new field:

protected final java.beans.PropertyChangeSupport this$PropertyChangeSupport = new java.beans.PropertyChangeSupport(this)"

Also adds support methods:

public void addPropertyChangeListener(java.beans.PropertyChangeListener)
public void addPropertyChangeListener(String, java.beans.PropertyChangeListener)
public void removePropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(String, java.beans.PropertyChangeListener)
public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
Parameters
declaringClass:ClassNode

the class to which we add the support field and methods

createBindableStatementback to summary
protected Statement createBindableStatement(PropertyNode propertyNode, Expression fieldExpression)

Creates a statement body similar to: this.firePropertyChange("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(ClassNode classNode, PropertyNode propertyNode)
createSetterMethodback to summary
protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock)

Creates a setter method with the given body.

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

hasBindableAnnotationback to summary
public static boolean hasBindableAnnotation(AnnotatedNode node)

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

Parameters
node:AnnotatedNode

the node to check

Returns:boolean

true if the node is bindable

needsPropertyChangeSupportback to summary
protected boolean needsPropertyChangeSupport(ClassNode declaringClass, SourceUnit sourceUnit)

Snoops through the declaring class and all parents looking for methods void addPropertyChangeListener(PropertyChangeListener), void removePropertyChangeListener(PropertyChangeListener), and void firePropertyChange(String, Object, Object). If any are defined all must be defined or a compilation error results.

Parameters
declaringClass:ClassNode

the class to search

sourceUnit:SourceUnit

the source unit, for error reporting. @NotNull.

Returns:boolean

true if property change support should be added

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

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, String propertyName)