Class ConstructorExampleGen

java.lang.Object
de.japkit.test.members.constructor.ConstructorExampleGen

@ConstructorTrigger(shadow=true)
@Generated(src="de.japkit.test.members.constructor.ConstructorExample")
public class ConstructorExampleGen
extends java.lang.Object
The generated class for the example.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    (package private) int field1
    Copies the fields from ConstructorExample.
    (package private) java.lang.String field2
    Copies the fields from ConstructorExample.
    (package private) java.lang.String field3
    Copies the fields from ConstructorExample.
  • Constructor Summary

    Constructors 
    Constructor Description
    ConstructorExampleGen()
    A parameterless constructor.
    ConstructorExampleGen​(int dummy, int field1, java.lang.String field2, java.lang.String field3)
    The same as #ConstructorTemplate(SrcType).
    ConstructorExampleGen​(int field1, java.lang.String field2, java.lang.String field3)
    A constructor that has the fields of the annotated class (MembersExample) as parameters and assigns them to the according generated fields.
    ConstructorExampleGen​(java.lang.String field2)
    For constructors with at least one parameter, the Constructor annotation is not necessary.
  • Method Summary

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • ConstructorExampleGen

      public ConstructorExampleGen()
      A parameterless constructor. When it is generated in the target class, the name will we be adjusted accordingly.

      The Constructor annotation is required for disambiguation when generating a default constructor.

    • ConstructorExampleGen

      public ConstructorExampleGen​(java.lang.String field2)
      For constructors with at least one parameter, the Constructor annotation is not necessary.
    • ConstructorExampleGen

      public ConstructorExampleGen​(int field1, java.lang.String field2, java.lang.String field3)
      A constructor that has the fields of the annotated class (MembersExample) as parameters and assigns them to the according generated fields.

      The parameter order depends on the result of TypeElement#getEnclosedElements(), which is used in fields function. Usually, this will be the same order as in the source code of ConstructorExample. However, during incremental build in Eclipse, you may sometimes experience a different order. If this happens, please do a clean build.

      See Also:
      Eclipse Bug 300408, Eclipse Bug 500589
    • ConstructorExampleGen

      public ConstructorExampleGen​(int dummy, int field1, java.lang.String field2, java.lang.String field3)
      The same as #ConstructorTemplate(SrcType). But this time, a CodeFragment is called for generating the field assignment code. A CodeFragment is basically a function that creates code.

      By using CodeFragments, arbitrary complex constructors and methods can be generated. But as in manual programming, it might be sometimes better to split them into multiple (private) methods then.

      Note that there a important differences between a CodeFragment and a function that returns a string. For example, CodeFragments provide support for adding import statements to the generated class. Furthermore, they are evaluated lazily, when the generated class is finally written. So, do not use simple string functions when generating method or constructor bodies, but always CodeFragments.