templates.innerBuildert Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JavaForger Show documentation
Show all versions of JavaForger Show documentation
JavaForger can create source code from templates using existing java classes as input.
<#if !constructors?? | constructors?size < 1>
public ${class.name}() {
// empty constructor which would otherwise be invisible due to the constructor receiving the builder.
}
#if>
private ${class.name}(Builder builder) {
<#list fields as field>
this.${field.name} = builder.${field.name} == null ? this.${field.name} : builder.${field.name};
#list>
}
/**
* Creates builder to build {@link ${class.name}}.
* @return created builder
*/
public static Builder builder() {
return new Builder();
}
/**
* Builder to build {@link ${class.name}}.
*/
public static final class Builder {
<#list fields as field>
private ${field.type} ${field.name}<#if field.defaultInit??> = ${field.defaultInit}#if>;
#list>
private Builder() {
// Builder should only be constructed via the parent class
}
<#list fields as field>
public Builder ${field.name}(${field.type} ${field.name}) {
<#if field.collection>
this.${field.name}.clear();
this.${field.name}.addAll(${field.name});
<#else>
this.${field.name} = ${field.name};
#if>
return this;
}
#list>
public ${class.name} build() {
return new ${class.name}(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy