generate builder pattern code in intellij

Use: Replace Constructor with Builder

  1. Place the caret at the constructor invocation to be replaced.
  2. Open Replace Constructor with Builder dialog box by choosing Refactor | Replace Constructor with Builder on the main menu, or on the context menu of the selection.
    The dialog box shows the list of constructor parameters to be passed to the builder, and the suggested name of a new builder.
  3. In the Parameters to pass to the builder list, optionally change the suggested setter names, and specify whether you want to initialize the generated fields in the builder.
    If you specify an initial value that matches the parameter value in the constructor invocation, you can skip setter method for such parameter by selecting the Optional Setter check box.
  4. Specify which builder are you going to use. If you select the Create new radio button, IntelliJ IDEA will generate a new builder, with the specified name, located in the specified package.
    If you select the Use existing radio button, find the desired builder class in your project.
  5. To review the intended changes and make final corrections prior to the refactoring, click Preview. To apply the changes immediately, click Refactor.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s