Class MethodExampleGen

java.lang.Object
de.japkit.test.members.method.MethodExampleGen

@MethodTrigger(shadow=true)
@Generated(src="de.japkit.test.members.method.MethodExample")
public class MethodExampleGen
extends java.lang.Object
The generated class for the example.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    private int someInt
    As shown in FieldTemplate, the fields are copied from the annotated class.
    private java.lang.String someString
    As shown in FieldTemplate, the fields are copied from the annotated class.
    private java.util.List<java.lang.String> someStringList
    As shown in FieldTemplate, the fields are copied from the annotated class.
    private java.util.Map<java.lang.String,​java.lang.String> someStringMap
    As shown in FieldTemplate, the fields are copied from the annotated class.
  • Constructor Summary

    Constructors 
    Constructor Description
    MethodExampleGen()  
  • Method Summary

    Modifier and Type Method Description
    int add​(int number1, int number2)
    Generates a method with fixed parameter list, name and return type.
    boolean equals​(java.lang.Object obj)
    Generates an equals method based on Objects.equals(Object, Object).
    int getSomeInt()  
    java.lang.String getSomeString()  
    java.util.List<java.lang.String> getSomeStringList()  
    java.util.Map<java.lang.String,​java.lang.String> getSomeStringMap()  
    int hashCode()
    Generates a hashCode method based on Objects.hash(Object...).
    void setSomeInt​(int someInt)  
    void setSomeString​(java.lang.String someString)  
    void setSomeStringList​(java.util.List<java.lang.String> someStringList)  
    void setSomeStringMap​(java.util.Map<java.lang.String,​java.lang.String> someStringMap)  

    Methods inherited from class java.lang.Object

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

    • someString

      private java.lang.String someString
      As shown in FieldTemplate, the fields are copied from the annotated class. They are used later to generate some meaningful methods.
    • someInt

      private int someInt
      As shown in FieldTemplate, the fields are copied from the annotated class. They are used later to generate some meaningful methods.
    • someStringList

      private java.util.List<java.lang.String> someStringList
      As shown in FieldTemplate, the fields are copied from the annotated class. They are used later to generate some meaningful methods.
    • someStringMap

      private java.util.Map<java.lang.String,​java.lang.String> someStringMap
      As shown in FieldTemplate, the fields are copied from the annotated class. They are used later to generate some meaningful methods.
  • Constructor Details

  • Method Details

    • getSomeString

      public java.lang.String getSomeString()
      Returns:
    • setSomeString

      public void setSomeString​(java.lang.String someString)
      Parameters:
      someString -
    • getSomeInt

      public int getSomeInt()
      Returns:
    • setSomeInt

      public void setSomeInt​(int someInt)
      Parameters:
      someInt -
    • getSomeStringList

      public java.util.List<java.lang.String> getSomeStringList()
      Returns:
    • setSomeStringList

      public void setSomeStringList​(java.util.List<java.lang.String> someStringList)
      Parameters:
      someStringList -
    • getSomeStringMap

      public java.util.Map<java.lang.String,​java.lang.String> getSomeStringMap()
      Returns:
    • setSomeStringMap

      public void setSomeStringMap​(java.util.Map<java.lang.String,​java.lang.String> someStringMap)
      Parameters:
      someStringMap -
    • add

      public int add​(int number1, int number2)
      Generates a method with fixed parameter list, name and return type.

      Since the body code is simple, it can be easily written as bodyCode annotation value.

      Since the method has a non-void return type, the method template returns 0 as dummy value. Alternatively, the method template can be made abstract.

      To demonstrate the usage of surrounding code fragments, the code body is wrapped into a try-catch that catches every Exception and rethrows it is RuntimeException. See rethrowAsRuntimeException.

    • hashCode

      public int hashCode()
      Generates a hashCode method based on Objects.hash(Object...).
      • The method template is annotated with Override. This annotation will be copied onto the generated method.
      • To not have to use the qualified name java.util.Objects, it is "imported". Japkit will take care of adding the import statement to the generated class.
      • When generating the code body, it is necessary to iterate over the fields, since the result shall look like return Objects.hash(field1, field2, field3, ...); For this, bodyIterator is used, which calls the fields function here to determine the collection to iterate on. bodyCode is just the name of the field. The list of fields is separated by "," (bodySeparator) and surrounded by "return Objects.hash(" (bodyBeforeIteratorCode) and ")" (bodyAfterIteratorCode).
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      Generates an equals method based on Objects.equals(Object, Object).

      This is quite similar to generating hashCode(): It iterates over the fields and adds some code for each field. But the code to be generated has mutltiple lines, which is impossible or at least unreadable when put into annotation values. Thus, as an alternative syntax, bodyBeforeIteratorCode, bodyCode, bodyAfterIteratorCode and others can be put into the javadoc comment. Please note the special syntax:

      • The prefix japkit. is necessary to make the "tags" recognizable to japkit at all.
      • Since the bodyBeforeIteratorCode has multiple lines, the <pre> tag is required to keep the line breaks and indentations.
      • The <ul> / <li> notation is for keeping this javadoc comment formatted as it is in the IDE.
      • <li>japkit.code is an alternative to @japkit.code. It has proven to be more resistant to re-formatting applied by the IDE (especially indentation).
      Note that this syntax is not only preferable for multiline code, but also if your are struggling with escaping of quotation marks in the code.

      Also note that the complete <ul> Block will be removed by japkit when the method comment is generated. So, it is only in the template, where it belongs.

      Overrides:
      equals in class java.lang.Object