template.builder.builder.vm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of annotation-processor Show documentation
Show all versions of annotation-processor Show documentation
A library that generates Builder classes for annotated POJOs
package ${descriptor.packageName}.builder;
import com.gitlab.tguseynov.buildersourcegeneratorlib.builder.Builder;
public class ${descriptor.className}Builder implements Builder<${descriptor.fullClassName}>
{
private InnerBuilder builder;
private ${descriptor.className}Builder(InnerBuilder builder)
{
this.builder = builder;
}
public static $descriptor.interfaces.get(0).interfaceName start()
{
return new InnerBuilder();
}
public static class InnerBuilder implements#foreach($interface in $descriptor.interfaces) ${interface.interfaceName}#if($foreach.hasNext),#end#end
{
#foreach($field in $descriptor.fields)
private ${field.type} ${field.name};
#end
private InnerBuilder()
{
}
#foreach($setter in $descriptor.setters)
public ${descriptor.className}Builder.${setter.returnType} set${setter.field.name.substring(0, 1).toUpperCase()}${setter.field.name.substring(1)}(${setter.field.type} ${setter.field.name})
{
this.${setter.field.name} = ${setter.field.name};
return this;
}
#end
public ${descriptor.className}Builder finish()
{
return new ${descriptor.className}Builder(this);
}
}
public ${descriptor.fullClassName} build()
{
${descriptor.fullClassName} obj = new ${descriptor.fullClassName}();
#foreach($field in $descriptor.fields)
obj.set${field.name.substring(0, 1).toUpperCase()}${field.name.substring(1)}(builder.$field.name);
#end
return obj;
}
#foreach($interface in $descriptor.interfaces)
interface ${interface.interfaceName}
{
#foreach($setter in $interface.setters)
${descriptor.className}Builder.${setter.returnType} set${setter.field.name.substring(0, 1).toUpperCase()}${setter.field.name.substring(1)}(${setter.field.type} ${setter.field.name});
#end
#if($interface.optionalInterface)
${descriptor.className}Builder finish();
#end
}
#end
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy