groovy.beans
Class BindableASTTransformation

Field Summary
 ClassNode boundClassNode
           
 ClassNode pcsClassNode
           
 FieldNode pcsField
           
 
Constructor Summary
BindableASTTransformation()
           
 
Method Summary
void addListenerToClass(SourceUnit source, AnnotationNode node, ClassNode classNode)
          
void addListenerToProperty(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field)
          
void addPropertyChangeSupport(ClassNode declaringClass)
           Adds the necessary field and methods to support property change support.
Statement createBindableStatement(PropertyNode propertyNode, Expression fieldExpression)
           Creates a statement body similar to: pcsField.firePropertyChange("field", field, field = value)
void createListenerSetter(SourceUnit source, AnnotationNode node, ClassNode classNode, PropertyNode propertyNode)
          
void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock)
           Creates a setter method with the given body.
static boolean hasBindableAnnotation(AnnotatedNode node)
           The found or created PropertyChangeSupport field
boolean needsPropertyChangeSupport(ClassNode declaringClass)
           Snoops through the declaring class and all parents looking for a field of type PropertyChangeSupport.
void visit(def nodes, SourceUnit source)
           Handles the bulk of the processing, mostly delegating to other methods.
 

Constructor Detail

BindableASTTransformation

BindableASTTransformation()


Method Detail

addListenerToClass

void addListenerToClass(SourceUnit source, AnnotationNode node, ClassNode classNode)


addListenerToProperty

void addListenerToProperty(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field)


addPropertyChangeSupport

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()

param:
declaringClass the class to which we add the support field and methods


createBindableStatement

Statement createBindableStatement(PropertyNode propertyNode, Expression fieldExpression)
Creates a statement body similar to: pcsField.firePropertyChange("field", field, field = value)
param:
propertyNode the field node for the property
param:
fieldExpression a field expression for setting the property value
return:
the created statement


createListenerSetter

void createListenerSetter(SourceUnit source, AnnotationNode node, ClassNode classNode, PropertyNode propertyNode)


createSetterMethod

void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock)
Creates a setter method with the given body.
param:
declaringClass the class to which we will add the setter
param:
propertyNode the field to back the setter
param:
setterName the name of the setter
param:
setterBlock the statement representing the setter block


hasBindableAnnotation

public static boolean hasBindableAnnotation(AnnotatedNode node)
The found or created PropertyChangeSupport field


needsPropertyChangeSupport

boolean needsPropertyChangeSupport(ClassNode declaringClass)
Snoops through the declaring class and all parents looking for a field of type PropertyChangeSupport. Remembers the field and returns false if found otherwise returns true to indicate that such support should be added.
param:
declaringClass the class to search
return:
true if property change support should be added


visit

public void visit(def nodes, SourceUnit source)
Handles the bulk of the processing, mostly delegating to other methods.
param:
nodes the ast nodes
param:
source the source unit for the nodes