Class FieldExampleGen

java.lang.Object
de.japkit.test.members.field.FieldExampleGen

@FieldTrigger(shadow=true)
@Generated(src="de.japkit.test.members.field.FieldExample")
public class FieldExampleGen
extends java.lang.Object
The generated class for the example.
  • 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 class FieldExample.
    private java.lang.String someString
    A field for every field in the annotated class FieldExample.
    private java.util.List<java.lang.String> someStringList
    A field for every field in the annotated class FieldExample.
  • 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)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • fixedField

      private java.lang.String fixedField
      A 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 someString
      A field for every field in the annotated class FieldExample.

      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 the CodeFragment notNullCheck. For FieldExample.someString this will result in

               if (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 field FieldExample.someStringList this will result in

               this.someStringList = new ArrayList<>(someStringList);
               
               
    • someInt

      private int someInt
      A field for every field in the annotated class FieldExample.

      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 the CodeFragment notNullCheck. For FieldExample.someString this will result in

               if (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 field FieldExample.someStringList this will result in

               this.someStringList = new ArrayList<>(someStringList);
               
               
    • someStringList

      private java.util.List<java.lang.String> someStringList
      A field for every field in the annotated class FieldExample.

      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 the CodeFragment notNullCheck. For FieldExample.someString this will result in

               if (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 field FieldExample.someStringList this will result in

               this.someStringList = new ArrayList<>(someStringList);
               
               
    • FIELD_NAMES

      public static final 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.
      • 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

    • 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

        public FieldExampleGen someString​(java.lang.String someString)
        Parameters:
        someString - the new value for someString
      • getSomeInt

        public int getSomeInt()
        Returns:
        the value of someInt
      • someInt

        public FieldExampleGen someInt​(int someInt)
        Parameters:
        someInt - the new value for someInt
      • getSomeStringList

        public java.util.List<java.lang.String> getSomeStringList()
        Returns:
        the value of someStringList
      • someStringList

        public FieldExampleGen someStringList​(java.util.List<java.lang.String> someStringList)
        Parameters:
        someStringList - the new value for someStringList