|
lombok-pg - | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||
@Target(value=TYPE) @Retention(value=SOURCE) public @interface Builder
Put on any type to make lombok-pg create a fluent interface builder for it.
Before:
@lombok.Builder
class Foo {
private final String a;
private final int b;
private String optionalC = "default";
private java.util.List<java.lang.Long> optionalD;
}
After:
class Foo {
private final String a;
private final int b;
private String optionalC;
private java.util.List<java.lang.Long> optionalD;
private Foo(final $Builder builder) {
super();
this.a = builder.a;
this.b = builder.b;
this.optionalVal1 = builder.optionalVal1;
this.optionalVal2 = builder.optionalVal2;
}
public static interface $ADef {
public $BDef a(final String a);
}
public static interface $BDef {
public $OptionalDef b(final int b);
}
public static interface $OptionalDef {
public $OptionalDef optionalC(final String optionalC);
public $OptionalDef optionalD(final java.util.List<java.lang.Long> optionalD);
public Foo build();
}
private static class $Builder implements $ADef, $BDef, $OptionalDef {
private String a;
private int b;
private String optionalC = "default";
private java.util.List<java.lang.Long> optionalD;
public $BDef a(final String a) {
this.a = a;
return this;
}
public $OptionalDef b(final int b) {
this.b = b;
return this;
}
public $OptionalDef optionalC(final String optionalC) {
this.optionalC = optionalC;
return this;
}
public $OptionalDef optionalD(final java.util.List<java.lang.Long> optionalD) {
this.optionalD = optionalD;
return this;
}
public Foo build() {
return new Foo(this);
}
}
public static $ADef create() {
return new $Builder();
}
}
Note: For each field that is a initialized collection( or map), the methods add/addAll( or put/putAll) will be
generated instead of the fluent-set method. This behavior can be disabled via convenientMethods = false.
| Optional Element Summary | |
|---|---|
boolean |
allowReset
Instruct lombok to generate a reset() method, so you can reuse the Builder instance. |
String[] |
callMethods
For each method listed here a method will appear in the builder. |
boolean |
convenientMethods
If you don't want collection-specific methods (add, addAll, put, putAll) you can disable them here. |
String[] |
exclude
Any fields listed here will not appear in the builder. |
String |
prefix
If specified all builder methods will be prefixed with this string. |
lombok.AccessLevel |
value
If you want the create-method to be non-public, you can specify an alternate access level here. |
public abstract lombok.AccessLevel value
public abstract String prefix
A common example would be @Builder(prefix="with") which will generate builder methods like
.withValue(value).
public abstract String[] exclude
public abstract boolean convenientMethods
public abstract String[] callMethods
A common example would be @Builder(callMethods={"execute", "toString"}) which would allow something
like:
Java.java().jar("test.jar").Xbootclasspatha("libs/asm.jar").execute()}
Java.java().jar("test.jar").Xbootclasspatha("libs/asm.jar").toString()}
public abstract boolean allowReset
Instruct lombok to generate a reset() method, so you can reuse the Builder instance.
Normally reusing the Builder instance is not necessary, therefore this feature is turned off by default.
|
lombok-pg - | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||