The current support of properties in Groovy beans does not auto-generate support for bound properties, a standard feature defined in the JavaBeans specification. This GEP proposes that there be some standard terse Groovy way to indicate to the compiler that such property support should be generated automatically
The proposed solution is to introduce a new annotation groovy.lang.BoundProperty. This annotation will have source level retention and will be valid only on fields.
When this property is present on one or more GroovyBeans properties then the class that contains the property will add a field $propertyChangeSupport of type java.beans.PropertyChangeSupport. Five methods will also be added, addPropertyChangeListener(PropertyChagneLsitener), removePropertyChangeListener(PropertyChagneListener), getPropertyChangeListeners(), addPropertyChangeListener(String, PropertyChagneLsitener), and removePropertyChangeListener(String, PropertyChagneListener). All of these methods will delegate directly to the appropriate method on $propertyChangeSupport. The auto-generated setter method will also call the firePropertyChanged(String, Object, Object} method of $propertyChangeSupport.
A compile time error MUST be raised when a property is declared as @BoundProperty where the default named setter method is also declared. (i.e.
A compile time error MUST be raised when a class has any properties declared as a @BoundProperty and any or all of the five automatically added methods are also declared in the class.
A compile time error SHOULD be raised when the @BoundProperty is used on a field with declared visibility, hence not a GroovyBean Property.
Classes compiles with this annotation SHOULD execute under a 1.4 JVM, although compilation using a Java 5 JVM MAY be required.
While it is possible to add such wiring today to a GroovyBeans property by essentially implementing it the way Java does, (i.e. explicitly do everything yourself), it would be cleaner if there was a way to declare a property as bound, and have groovy handle the wiring like it already does for simple property declarations. Either a language keyword or annotation would be possible ways to do it.
I am proposing the built in annotation because the addition of an additional language keyword may break older scripts where a previously unreserved keyword is now reserved. The use of syntactical punctuation is also not recommended since (a) there is no other example of using punctuation to add this aspect to a property and (b) because of that readability would suffer for those not familiar with the Groovy language.
I am also proposing annotations because I will be able to submit a proof of concept implementation myself much easier.
This enhancement will not be source code compatible with versions of Groovy prior to 1.1. The sole reason for this is the use of annotations. (use of a keyword or punctuation would similarly cause incompatibility).
In instances where a user wants to use a Groovy script with @BoundProperty notation they user will need to remove the annotation, and either (a) not use automatically generated PropertyChangeListeners or (b) implement them by hand.