With JavaForger you could use the template as given below to generate the setters. It does mean that you'll have to run a main method for every class that you want generate getters and setters for.
<#list fields as field>
/**
* Sets the ${field.name} of the {@link ${class.name}}.
*
* @param ${field.name} The input {@link ${field.nonPrimitiveType}}.
*/
public ${class.name} ${field.setter}(${field.type} ${field.name}) {
this.${field.name} = ${field.name};
return this;
}
</#list>
The code below executes the template above (setters.javat) for a class called "myClass.java" and merges the generated code with the inputclass. It will override existing setters if they exist.
JavaForgerConfiguration config = JavaForgerConfiguration.builder()
.withTemplate("setters.javat")
.withMergeClassProvider(ClassProvider.fromInputClass(s -> s))
.withOverride(true)
.build();
JavaForger.execute(config, "myClass.java");
You will have to add the location of "setters.javat" with:
StaticJavaForgerConfiguration.addTemplateLocation("my/location/");
The project can be found here: https://github.com/daanvdh/JavaForger.