| From | Sent On | Attachments |
|---|---|---|
| Paulo Gabriel Poiati | Jul 10, 2010 4:07 pm | .diff |
| Paul King | Jul 11, 2010 3:36 pm | |
| Guillaume Laforge | Jul 12, 2010 1:54 am | |
| Erik Pragt | Jul 12, 2010 2:28 am | |
| Dierk König | Jul 12, 2010 2:31 am | |
| Guillaume Laforge | Jul 12, 2010 2:33 am | |
| Martin C. Martin | Jul 12, 2010 6:35 am | |
| Paulo Gabriel Poiati | Jul 12, 2010 8:20 am | |
| Hamlet D'Arcy | Jul 12, 2010 11:43 pm | |
| Alex Tkachman | Jul 12, 2010 11:49 pm | |
| Hamlet D'Arcy | Jul 14, 2010 1:46 am |
| Subject: | [groovy-dev] What about a @Mutable ast transformation (with implementation) | |
|---|---|---|
| From: | Paulo Gabriel Poiati (paul...@gmail.com) | |
| Date: | Jul 10, 2010 4:07:55 pm | |
| List: | org.codehaus.groovy.dev | |
| Attachments: | ||
Hello, I think it's a good idea to have an ast transformation that create the toString, equals, hashCode and positional args constructor (like @Immutable does). Also, because it's mutable it can have untyped properties and not all properties need to be initialized in the constructor.
I was searching for something like that, and I found this: http://archive.codehaus.org/lists/org.codehaus.groovy.user/msg/1aae...@mail.gmail.com
Paulo King suggested the @Mutable ast.
I did an implementation, based in the current groovy trunk (rev 20439). Most of the work was stole from Paul King @Immutable implementation).
What differs from @Immutable: - It's mutable, implying that nor properties or class are final, and it provide setters methods. - Allow untyped properties. - Objects are passed by reference in the constructor, not wrapped or cloned. - Hashcode is not cached. - Constructor arguments are optional. - If a class is annotated as @Mutable and @Immutable an exception is throw. - Inheritance is possible
The patch is attached...
Example:
*@Mutable class Customer {* * String first, last* * int age* * Date since* * Collection favItems = ['Food']* * def object * *}* * * *def d = new Date()* *def anyObject = new Object()* *def c1 = new Customer(first:'Tom', last:'Jones', age:21, since:d, favItems:['Books', 'Games'], object: anyObject)* *def c2 = new Customer('Tom', 'Jones', 21, d, ['Books', 'Games'], anyObject) * *assert c1 == c2* * * * * *def c3 = new Customer(last: 'Jones', age: 21)* *def c4 = new Customer('Tom', 'Jones')* *assert null == c3.since* *assert 0 == c4.age* *assert c3.favItems == ['Food'] && c4.favItems == ['Food']*
I will appreciate any kind of feedback.
Tks !
[]'s Paulo Poiati
blog.paulopoiati.com
--------------------------------------------------------------------- To unsubscribe from this list, please visit:






.diff