Replace Constructor With Builder Dialog Box
See Also
Use this dialog box to replace a public constructor with references to a newly created builder class. You can use the Refactor command to introduce a builder class that calls the hidden constructor and replaces existing calls to the constructor with calls to the builder class.
The Replace Constructor With Builder dialog box appears after you have chosen the Refactor > Replace Constructor With Builder command while having a constructor selected in the Source Editor.
The Replace Constructor With Builder dialog box has the following fields:
- Parameter. Contains the list of parameters detected in the constructor, which will be replaced with the builder fields.
- Setter Name. Contains the list of setter names to be created in the builder class, which the IDE suggests. To edit a name, double-click the appropriate column line.
- Default Value. Contains the list of default values for initializing the builder fields. To specify a value, double-click the appropriate column line.
- Optional Setter. If selected, a setter method for this field in the builder invocation is omitted when the specified default value of a field matches the parameter value in the constructor invocation. Otherwise the corresponding setter method is shown.
- Builder Class Name. Contains the name of the builder class to be applied.
Specify the new name of the builder class by modifying this field.
Unless you click Refactor, you need to follow these steps
to complete the refactoring:
- Click Preview.
The Refactoring
window opens and displays a tree view of the code to be affected by the refactoring.
- Check the items displayed in the Refactoring window to make sure that you want them
all changed. Clear the checkbox next to any parts of the code that
you do not want changed.
- Click Refactor.
- You should always perform a clean build after completing
any refactoring commands. You can do a clean build by right-clicking the project's
node in the Projects window and choosing Clean and Build Project.
- See Also
- Refactoring: Quick Reference
- Replace Constructor With Factory Dialog Box
- Undoing Refactoring Changes
Legal Notices