Compatible with  IntelliJ IDEA
5 715
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.

Download plugin

General usage instructions

Select with on Generate menu (alt+ins on window, ctrl+n on mac)

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)
for (Field field : person.class.getDeclaredFields())
values.put(field.getName(), field.get(person));
} catch (IllegalAccessException e)
throw new AssertionError(\"shouldn\'t happen\");

Brilliant if you are using the builder plugin
Please  sign in  to leave a comment.