Annotation Type GeneratePojoBuilder
-
@Retention(CLASS) @Target({TYPE,METHOD,CONSTRUCTOR,ANNOTATION_TYPE}) public @interface GeneratePojoBuilderUse this annotation to trigger the code generation of a fluent pojo builder.
-
-
Field Summary
Fields Modifier and Type Fields Description static java.lang.StringDEFAULT_FACTORY_METHODstatic java.lang.StringDEFAULT_INCLUSION_PATTERNstatic java.lang.StringDEFAULT_NAMEstatic java.lang.StringDEFAULT_PACKAGEstatic java.lang.StringDEFAULT_SETTER_NAME
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.String[]excludePropertiesSpecifies which of the pojo's properties will be excluded from the generated builder.java.lang.String[]includePropertiesSpecifies which of the pojo's properties will be included into the generated builder.java.lang.StringintoPackageSpecifies the package of the generated builder.java.lang.Class<?>withBaseclassSpecifies the base class of the generated builder.java.lang.Class<?>withBuilderInterfaceSpecifies the generic builder interface of the generated builder.booleanwithBuilderPropertiesSpecifies whether the generated builder should define builder-based setter-methods using the builder interface.VisibilitywithConstructorSpecifies the visibility of the builder's constructor.booleanwithCopyMethodSpecifies whether a copy method should be generated.java.lang.StringwithFactoryMethodSpecifies the name of a static factory method added to the builder.booleanwithGenerationGapSpecifies whether the generation gap pattern is used.java.lang.StringwithNameSpecifies the name of the generated builder.java.lang.Class<?>withOptionalPropertiesSpecifies whether the generated builder should define optional-based setter-methods using the specified 'Optional' type.java.lang.StringwithSetterNamePatternSpecifies the name pattern of the generated setter-methods.java.lang.Class<?>withValidatorSpecifies the validator class that should be used to validate the created pojo.
-
-
-
-
withBuilderInterface
java.lang.Class<?> withBuilderInterface
Specifies the generic builder interface of the generated builder. This interface must declare exactly one type parameter and abuild()(or alternatively aget()) method having this type as return type.For example:
public interface Builder<T> { T build(); }- Returns:
- the generic interface of the generated builder or
Void, if no interface is specified
- Default:
- java.lang.Void.class
-
-
-
withBuilderProperties
boolean withBuilderProperties
Specifies whether the generated builder should define builder-based setter-methods using the builder interface.When set to
true, thewithBuilderInterface()must specify a valid interface.- Returns:
- whether the generated builder should define builder-based setter-methods
- Default:
- false
-
-
-
withOptionalProperties
java.lang.Class<?> withOptionalProperties
Specifies whether the generated builder should define optional-based setter-methods using the specified 'Optional' type.The 'Optional' type can have any name but must be interface-compatible with the following interface:
where T is the generic type parameter matching the property's type.public interface Optional<T> { T get(); boolean isPresent(); }Examples are Google Guava's com.google.common.base.Optional and java.util.Optional introduced with Java 8.
- Returns:
- the 'Optional' type used for generating the optional-based setter-methods, or
Voidif no optional-based setter-methods should be generated
- Default:
- java.lang.Void.class
-
-
-
withGenerationGap
boolean withGenerationGap
Specifies whether the generation gap pattern is used. If enabled this will generate two classes (instead of one), of which one contains the generated code. The other class is for handwritten code. To prevent it from being overwritten please move it out of the generated-sources folder. Default is "false".- Returns:
trueif the generation gap should be used
- Default:
- false
-
-
-
withCopyMethod
boolean withCopyMethod
Specifies whether a copy method should be generated. The copy method will take an instance of the built class and will copy all its fields into the builder. This allows it to easily change one or more fields of immutable objects.- Returns:
trueif a copy method should be generated
- Default:
- false
-
-
-
withFactoryMethod
java.lang.String withFactoryMethod
Specifies the name of a static factory method added to the builder. An asterisk will be replaced by the pojos simple name. Default is "" meaning not to generate this method.public class MyPojoBuilder { public static MyPojoBuilder myPojo() { return new MyPojoBuilder(); } }- Returns:
- the factory-method name
- Default:
- ""
-
-
-
withConstructor
Visibility withConstructor
Specifies the visibility of the builder's constructor.- Returns:
- the constructor's visibility
- Default:
- net.karneim.pojobuilder.Visibility.PUBLIC
-
-
-
withValidator
java.lang.Class<?> withValidator
Specifies the validator class that should be used to validate the created pojo. The class must define avalidatemethod having one parameter that is compatible with the pojo's type. If the validation fails, the method must throw some runtime exception (or one of its subclasses).This is an example of how a validator could look like:
public class MyPojoValidator { public void validate(Pojo pojo) { if ( - check if pojo is invalid -) { throw new RuntimeException("This pojo is invalid!"); } } }- Returns:
- the validator's class, or
Void, if no validator should be used.
- Default:
- java.lang.Void.class
-
-
-
includeProperties
java.lang.String[] includeProperties
Specifies which of the pojo's properties will be included into the generated builder. All properties that match any property pattern in the specified array will be included. All other non-mandatory properties will be excluded. Mandatory properties are those which are passed as constructor or factory method arguments. They will never be excluded, neither explicitly nor implicitly.The property pattern consists of a name pattern followed by an optional type pattern.
The syntax is
<name pattern>[:<type pattern>].The pattern supports the asterisk '*' wildcard character that matches any character.Default is '*'.
- Returns:
- the inclusion patterns
- Default:
- {"*"}
-
-
-
excludeProperties
java.lang.String[] excludeProperties
Specifies which of the pojo's properties will be excluded from the generated builder. All property that match any property pattern in the specified array will be excluded, except those that are mandatory. Mandatory properties are those which are passed as constructor or factory method arguments. They will never be excluded, neither explicitly nor implicitly.The property pattern consists of a name pattern followed by an optional type pattern.
The syntax is
<name pattern>[:<type pattern>].The pattern supports the asterisk '*' wildcard character that matches any character.Default is the empty array.
- Returns:
- the exclusion patterns
- Default:
- {}
-
-