opensource software
GenerateBuilder
Products:
IntelliJ IDEA,
Android Studio
Vendor:
Tim Tennant, Mike Dunford
Email:
Website:
N/A
License: http://www.opensource.org/licenses/bsd-license.php
Bugtracker page
Description:
This plugin adds builder actions to the generate menu (ctrl + n). Actions to generate builders and builder with methods.
- 'with methods' action (ctrl + shift + w) generates a withFieldName() method in current class for each of the classes fields you select (works like the generate getter/setter). The with method returns the current class.
- 'generate builder' action (alt + shift + b) generates a builder class in the current package for the current class, that has a withFieldName() method for each field in the class, and a build() method that constructs and returns a new instance of the class.
Downloads: 3239
Rating:
Participated in rating: 2
General usage instructions:
Select with on Generate menu (alt+ins on window, ctrl+n on mac)
Comments:
I was looking for a plugin to do exactly this, and found your plugin. It certainly is very useful, but I am missing one feature which would make my life much easier: it would be nice if every builder had a constructor taking the type you are building, in order to \"prepopulate\" the values in the map.
For example if you have a class Person and a PersonBuilder, you could do
Person existing = findPersonFromSomewhere();
Person updated = new PersonBuilder(existing).withName(\"new name\").build();
In stead of having to set every property which doesn\'t change in the existing person again...
It can be implemented like this:
public PersonBuilder(Person person)
{
try
{
for (Field field : person.class.getDeclaredFields())
{
field.setAccessible(true);
values.put(field.getName(), field.get(person));
}
} catch (IllegalAccessException e)
{
throw new AssertionError(\"shouldn\'t happen\");
}
}
Thanks,
Jan