Class FieldExampleGen
@FieldTrigger(shadow=true) @Generated(src="de.japkit.test.members.field.FieldExample") public class FieldExampleGen extends java.lang.Object
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String[]
FIELD_NAMES
To show some more complex initializer code, a constant field is generated here that has the array of all field names as value.private java.lang.String
fixedField
A field with fix name and type and with public getters and setters.private int
someInt
A field for every field in the annotated classFieldExample
.private java.lang.String
someString
A field for every field in the annotated classFieldExample
.private java.util.List<java.lang.String>
someStringList
A field for every field in the annotated classFieldExample
. -
Constructor Summary
Constructors Constructor Description FieldExampleGen()
-
Method Summary
Modifier and Type Method Description java.lang.String
getFixedField()
int
getSomeInt()
java.lang.String
getSomeString()
java.util.List<java.lang.String>
getSomeStringList()
void
setFixedField(java.lang.String fixedField)
FieldExampleGen
someInt(int someInt)
FieldExampleGen
someString(java.lang.String someString)
FieldExampleGen
someStringList(java.util.List<java.lang.String> someStringList)
-
Field Details
-
fixedField
private java.lang.String fixedFieldA field with fix name and type and with public getters and setters.While getters and setters could be generated as methods (see
MethodTemplate
), they are so common that japkit provides some more convenience for it.The field is initialized with the value "foobar".
-
someString
private java.lang.String someStringA field for every field in the annotated classFieldExample
.The setters are fluent style and return this for chaining.
For fields with a
NotNull
annotation, a null-check is added to the setter by calling theCodeFragment
notNullCheck
. ForFieldExample.someString
this will result inif (someString == null) { throw new IllegalArgumentException("someString must not be null."); } this.someString = someString;
For fields of mutable types, the
setterDefensiveCopy
is called to make a defensive copy in the setter. The code generated by that fragment "surrounds" the right hand side of the assignment in the setter. For example, for the fieldFieldExample.someStringList
this will result inthis.someStringList = new ArrayList<>(someStringList);
-
someInt
private int someIntA field for every field in the annotated classFieldExample
.The setters are fluent style and return this for chaining.
For fields with a
NotNull
annotation, a null-check is added to the setter by calling theCodeFragment
notNullCheck
. ForFieldExample.someString
this will result inif (someString == null) { throw new IllegalArgumentException("someString must not be null."); } this.someString = someString;
For fields of mutable types, the
setterDefensiveCopy
is called to make a defensive copy in the setter. The code generated by that fragment "surrounds" the right hand side of the assignment in the setter. For example, for the fieldFieldExample.someStringList
this will result inthis.someStringList = new ArrayList<>(someStringList);
-
someStringList
private java.util.List<java.lang.String> someStringListA field for every field in the annotated classFieldExample
.The setters are fluent style and return this for chaining.
For fields with a
NotNull
annotation, a null-check is added to the setter by calling theCodeFragment
notNullCheck
. ForFieldExample.someString
this will result inif (someString == null) { throw new IllegalArgumentException("someString must not be null."); } this.someString = someString;
For fields of mutable types, the
setterDefensiveCopy
is called to make a defensive copy in the setter. The code generated by that fragment "surrounds" the right hand side of the assignment in the setter. For example, for the fieldFieldExample.someStringList
this will result inthis.someStringList = new ArrayList<>(someStringList);
-
FIELD_NAMES
public static final java.lang.String[] FIELD_NAMESTo show some more complex initializer code, a constant field is generated here that has the array of all field names as value.- The initIterator tells to iterate over the fields of the annotated class.
- The initBeforeIteratorCode is the code to be generated before the iteration starts.
- The initAfterIteratorCode is the code to be generated after the iteration ends.
- The initCode is the code to be generated for each iteration. Here, it
is the name of the field from the annotated class in double quotes.
-
-
Constructor Details
-
FieldExampleGen
public FieldExampleGen()
-
-
Method Details
-
getFixedField
public java.lang.String getFixedField()- Returns:
- the value of fixedField
-
setFixedField
public void setFixedField(java.lang.String fixedField)- Parameters:
fixedField
- the new value for fixedField
-
getSomeString
public java.lang.String getSomeString()- Returns:
- the value of someString
-
someString
- Parameters:
someString
- the new value for someString
-
getSomeInt
public int getSomeInt()- Returns:
- the value of someInt
-
someInt
- Parameters:
someInt
- the new value for someInt
-
getSomeStringList
public java.util.List<java.lang.String> getSomeStringList()- Returns:
- the value of someStringList
-
someStringList
- Parameters:
someStringList
- the new value for someStringList
-