jastrachan | 2 Feb 09:44 2005

using annotations instead of a keyword for bean properties

Currently in Classic we have a keyword for making bean properties

class Person
     property String name
     property int age

which generates private fields and public getters/setters unless you 
explicitly define one.

The thing is, someone might want a bound property (which should 
probably be the default as its more useful), some way want unbound 
properties (if for some reason they really don't wanna fire events when 
properties change), vetoable properties, read-only, write-only, 
lazy-created-property etc.

So rather than a specific keyword; I'm thinking it'd be cleaner to use 
annotations to annotate a field declaration which can act as a way to 
make the getter/setter stuff, so that it is extensible or at least can 
be in 2.0 of Groovy - later on we could allow folks to define their own 
macros - but for 1.0 we define just one hard coded default 

class Person
    <at> property String name
    <at> property int age

further down the line we could consider adding  <at> unboundProperty or 
 <at> vetoableProperty.


One comment, in Java 5 annotations are typed, so the convention appears 
to be to use upper case names for annotations. So it might be better to 

class Person
    <at> Property String name
    <at> Property int age

then it matches the feel of Java 5 annotations?