Refactoring of field initializers, instance initializers and static constructors

  1. In Java a class can have multiple instance initializers and class initializers. In D there are no instance initializer and only one static ctor is allowed.
  2. In Java a field can be initialized in its declaration. The initialization can also include nearly every expression. In D an initializer must be a compile time module-local constant value.

Static ctors and initialization of static fields

If a static field initializer or a static initializer exists, TioPort generates a new static ctor, replacing the originals. This new static ctor contains all static field initializations and code of all static initializers. Every piece of code is placed in its own statement list.

Instance initializers and initialization of instance fields

If a non static field initializer of a instance initializer exist, TioPort generates a private method called "GENERATED_INSTANCE_INIT". All initializers and instance init code is moved into this method. Every piece of code is placed in its own statement list.

After this step all ctors are searched. If the ctor does not have a call to another ctor of this class ( called "this" ), a call to the init method is inserted at the beginning of the ctor.