Groovy 1.7.0

groovy.beans
Class VetoableASTTransformation

java.lang.Object
  groovy.beans.BindableASTTransformation
      groovy.beans.VetoableASTTransformation

@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
class VetoableASTTransformation
extends BindableASTTransformation

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 annotaton is detected it also adds support similar to what BindableASTTransformation would do.

author:
Danno Ferrin (shemnon)
author:
Chris Reeves


Field Summary
protected static ClassNode constrainedClassNode

protected ClassNode vcsClassNode

 
Fields inherited from class BindableASTTransformation
boundClassNode, pcsClassNode
 
Constructor Summary
VetoableASTTransformation()

 
Method Summary
protected void addVetoableChangeSupport(ClassNode declaringClass)

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

protected Statement createConstrainedStatement(PropertyNode propertyNode, Expression fieldExpression)

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

protected Statement createSetStatement(Expression fieldExpression)

Creates a statement body similar to: field = value

Used when the field is not also @Bindable

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

Creates a setter method with the given body.

static boolean hasVetoableAnnotation(AnnotatedNode node)

Convenience method to see if an annotated node is {

protected boolean needsVetoableChangeSupport(ClassNode declaringClass, SourceUnit sourceUnit)

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

void visit(ASTNode[] nodes, SourceUnit source)

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

 
Methods inherited from class BindableASTTransformation
addPropertyChangeSupport, createBindableStatement, createSetterMethod, hasBindableAnnotation, needsPropertyChangeSupport, visit
 
Methods inherited from class Object
wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll
 

Field Detail

constrainedClassNode

protected static ClassNode constrainedClassNode


vcsClassNode

protected ClassNode vcsClassNode


 
Constructor Detail

VetoableASTTransformation

VetoableASTTransformation()


 
Method Detail

addVetoableChangeSupport

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

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


createConstrainedStatement

protected Statement createConstrainedStatement(PropertyNode propertyNode, Expression fieldExpression)
Creates a statement body silimar to: this.fireVetoableChange("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


createSetStatement

protected Statement createSetStatement(Expression fieldExpression)
Creates a statement body similar to: field = value

Used when the field is not also @Bindable

param:
fieldExpression a field expression for setting the property value
return:
the created statement


createSetterMethod

protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock)
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

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


hasVetoableAnnotation

public static boolean hasVetoableAnnotation(AnnotatedNode node)
Convenience method to see if an annotated node is @Vetoable.
param:
node the node to check
return:
true if the node is constrained


needsVetoableChangeSupport

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.
param:
declaringClass the class to search
return:
true if vetoable change support should be added


visit

public void visit(ASTNode[] 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


 

Copyright © 2003-2009 The Codehaus. All rights reserved.