lombok-pg -

lombok
Annotation Type Builder


@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.
 

value

public abstract lombok.AccessLevel value
If you want the create-method to be non-public, you can specify an alternate access level here.

Default:
lombok.AccessLevel.PUBLIC

prefix

public abstract String prefix
If specified all builder methods will be prefixed with this string.

A common example would be @Builder(prefix="with") which will generate builder methods like .withValue(value).

Default:
""

exclude

public abstract String[] exclude
Any fields listed here will not appear in the builder.

Default:
{}

convenientMethods

public abstract boolean convenientMethods
If you don't want collection-specific methods (add, addAll, put, putAll) you can disable them here.

Default:
true

callMethods

public abstract String[] callMethods
For each method listed here a method will appear in the builder.

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()}
 

Default:
{}

allowReset

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.

Default:
false

lombok-pg -

Copyright © 2010-2011 Philipp Eichhorn, licensed under the MIT licence.