Annotation Type PropertyDefinition
-
@Retention(RUNTIME) @Target(FIELD) public @interface PropertyDefinition
Annotation defining a property for code generation.This annotation must be used on all private instance variables that should be treated as properties.
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description String
alias
An alternative name for the property.String
builderType
The exposed type of the property in the builder and associated constructor.String
equalsHashCodeStyle
The configuration for equals and hash code.String
get
The style of the method used to query the property.boolean
overrideGet
Whether the generated getter should be declared with theOverride
annotation.boolean
overrideSet
Whether the generated setter should be declared with theOverride
annotation.String
set
The style of the method used to mutate the property.String
toStringStyle
The configuration for toString.String
type
The exposed type of the property.String
validate
The validator to use.
-
-
-
Element Detail
-
alias
String alias
An alternative name for the property.The property can be looked up using the specified alias. The primary name is unaffected, and the alias is only used in certain circumstances. For example,
bean.metaProperty("alias")
andbean.property("alias")
will both work, as will getting and setting via an immutable bean builder.This attribute is most useful in handling change from serialized forms.
- Returns:
- the alias of the property, defaulted to ''
- Default:
- ""
-
-
-
get
String get
The style of the method used to query the property.The style is a string describing the getter, typically used for code generation. By default this is 'smart' which will use the source code knowledge to determine what to generate. This will be a method of the form
isXxx()
forboolean
andgetXxx()
for all other types.Supported style strings are:
- '' - do not generate any form of getter
- 'smart' - process intelligently - 'is' for boolean and 'get' for other types
- 'private' - process as per 'smart' but set scope as private
- 'package' - process as per 'smart' but set scope as package/default
- 'protected' - process as per 'smart' but set scope as protected
- 'is' - generates isXxx()
- 'get' - generates getXxx()
- 'clone' - generates getXxx() with a clone of the field (assumed to be of the correct type)
- 'cloneCast' - generates getXxx() with a clone of the field with a cast to the property type
- 'optional' - generate getXxx() returning a Java 8
Optional
wrapper around the field, where the field itself is nullable instead of optional.OptionalDouble
,OptionalInt
andOptionalLong
are also handled - 'optionalGuava' - generate getXxx() returning a Guava
Optional
wrapper around the field, where the field itself is nullable instead of optional - 'field' - generates direct access to the field, enabling a weird manual getter
- 'manual' - a method named getXxx() must be manually provided at package scope or greater
- Returns:
- the getter style, defaulted to 'smart'
- Default:
- "smart"
-
-
-
set
String set
The style of the method used to mutate the property.The style is a string describing the mutator, typically used for code generation. By default this is 'smart' which will use the source code knowledge to determine what to generate. This will be a method of the form
setXxx()
for all types unless the field isfinal
. If the field is a finalCollection
orMap
of a known type then a set method is generated usingaddAll
orpuAll
Standard style strings are:
- '' - do not generate any form of setter
- 'smart' - process intelligently - uses 'set' unless final, when it will use 'setClearAddAll' for common list types or 'setClearPutAll' for common map types and FlexiBean
- 'private' - process as per 'smart' but set scope as private
- 'package' - process as per 'smart' but set scope as package/default
- 'protected' - process as per 'smart' but set scope as protected
- 'set' - generates setXxx()
- 'setClearAddAll' - generates setXxx() using field.clear() and field.addAll(newData)
- 'setClearPutAll' - generates setXxx() using field.clear() and field.putAll(newData)
- 'bound' - generates a bound property with
PropertyChangeSupport
- 'field' - generates direct access to the field, enabling a weird manual setter
- 'manual' - a method named setXxx() must be manually provided at package scope or greater
- a pattern, see below
A pattern can be used for special behaviour. The pattern is a complete piece of code. For example, 'new Foo($value)' or '$field = $value.clone()'.
'$field' for the field to copy into.
'$value' for the value to copy from.
'<>' for the generics of the type including angle brackets.
'\n' for a new line (all lines must then include semi-colons).- Returns:
- the setter style, defaulted to 'smart'
- Default:
- "smart"
-
-
-
type
String type
The exposed type of the property.The style is used to control the exposed type of the property in getters and setters, or similar.
This is used when the type of the field is not the same as the type that should be used in public methods such as getters and setters.
By default, the declared type will be used as the exposed type.
- Returns:
- the exposed type, defaulted to 'smart'
- Default:
- "smart"
-
-
-
builderType
String builderType
The exposed type of the property in the builder and associated constructor.The style is used to control the exposed type of the property in immutable builders and associated constructors, or similar.
This is used when the type of the field is not the same as the type that should be used in public methods such as builder setters.
By default, the declared type will be used as the exposed type.
This is typically used to add '? extends' to collection types.
- Returns:
- the builder type, defaulted to 'smart'
- Default:
- "smart"
-
-
-
equalsHashCodeStyle
String equalsHashCodeStyle
The configuration for equals and hash code.This flag controls generation of the
equals
andhashCode
methods. The default is 'smart'.Standard strings are:
- 'omit' - omit this property from equals and hashCode
- 'smart' - process intelligently, equivalent to 'field' for immutable and 'getter' for mutable
- 'getter' - include in equals and hashCode using the getter
- 'field' - include in equals and hashCode using the field
- Returns:
- the equals/hashCode style, defaulted to 'smart'
- Default:
- "smart"
-
-
-
toStringStyle
String toStringStyle
The configuration for toString.This flag controls generation of the
toString
method. The default is 'smart'.Standard strings are:
- 'omit' - omit this property from toString
- 'smart' - process intelligently, equivalent to 'field' for immutable and 'getter' for mutable
- 'getter' - include in toString using the getter
- 'field' - include in toString using the field
- Returns:
- the toString style, defaulted to 'smart'
- Default:
- "smart"
-
-
-
validate
String validate
The validator to use.The property value may be validated by specifying this attribute. By default no validation is performed. The code generator places the validation into the set method and ensures that new objects are validated correctly.
Custom validations, are written by writing a static method and referring to it. For example,
public void checkMyValue(Integer val, String propertyName) ...
The method generally has avoid
return, throwing an exception if validation fails. There must be two arguments, the value and the property name. The value may be the property type or a superclass (like Object). The property name should be a String.Standard validation strings are:
- '' - do not generate any form of validation
- 'notNull' - suitable for checking that the value is non-null, calls JodaBeanUtils.notNull() which throws an IllegalArgumentException
- 'notEmpty' - suitable for checking that a string/collection/map is non-null and non-empty, calls JodaBeanUtils.notEmpty() which throws an IllegalArgumentException
- 'notBlank' - suitable for checking that a string is non-null and non-blank, calls JodaBeanUtils.notBlank() which throws an IllegalArgumentException
- '{className}.{staticMethodName}' - a custom validation method, described above
- Returns:
- the validation, defaulted to ''
- Default:
- ""
-
-