Class MethodExampleGen
@MethodTrigger(shadow=true) @Generated(src="de.japkit.test.members.method.MethodExample") public class MethodExampleGen extends java.lang.Object
-
Field Summary
Fields Modifier and Type Field Description private int
someInt
As shown inFieldTemplate
, the fields are copied from the annotated class.private java.lang.String
someString
As shown inFieldTemplate
, the fields are copied from the annotated class.private java.util.List<java.lang.String>
someStringList
As shown inFieldTemplate
, the fields are copied from the annotated class.private java.util.Map<java.lang.String,java.lang.String>
someStringMap
As shown inFieldTemplate
, 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 onObjects.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 onObjects.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)
-
Field Details
-
someString
private java.lang.String someStringAs shown inFieldTemplate
, the fields are copied from the annotated class. They are used later to generate some meaningful methods. -
someInt
private int someIntAs shown inFieldTemplate
, 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> someStringListAs shown inFieldTemplate
, 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> someStringMapAs shown inFieldTemplate
, the fields are copied from the annotated class. They are used later to generate some meaningful methods.
-
-
Constructor Details
-
MethodExampleGen
public MethodExampleGen()
-
-
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 onObjects.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 thefields
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 classjava.lang.Object
- The method template is annotated with
-
equals
public boolean equals(java.lang.Object obj)Generates an equals method based onObjects.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).
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 classjava.lang.Object
- The prefix
-