I would like to make a macro that would essentially expand this:
@WithB开发者_运维问答asicConstructor
class Person {
private String name
private String address
}
into this:
class Person {
private String name
private String address
Person(String name, String address) {
this.name = name
this.address = address
}
}
I've been reading through the code for @Immutable
to get a feel for how it is done. Has anyone used the new AstBuilder?
Any ideas how to implement this? Is there a preferred option between AstBuilder for string/code/spec ?
You could use (or copy) @groovy.transform.TupleConstructor
from groovy 1.8.
Regarding preferences... I like the buildFromSpec
, it leads to fewer surprises.
But I'd suggest you try the buildFromCode
, test its limitations and quirks, play a little with all of them.
精彩评论