Reputation: 1833
I am looking for Groovy AST transformation that would generate builder pattern code inside my class.
I know there are something like @Canonnical
or @ToString
or @EqualsAndHashCode
enhancers that automatically generate useful methods and hoped if there would be @GenerateBuilder. I want to use it something like this:
//Groovy code:
@GenerateBuilder
@CompileStatic
class Person {
String name
int age
Long id
String createdBy
}
//then in Java code:
Person p = Person.newBuilder()
.withName("pawel")
.withAge(19)
.withId(11123)
.withCreatedBy("system")
.build();
Upvotes: 3
Views: 532
Reputation: 171084
There's nothing prior to 2.3 that will do this
But groovy 2.3 has a new @Builder
annotation
https://github.com/groovy/groovy-core/blob/master/src/main/groovy/transform/builder/Builder.java
Upvotes: 5