The Extract Parameter refactoring is used to add a new parameter to a function declaration and to update the function calls accordingly.
To extract parameter
- In the editor, place the cursor within the expression or local variable declaration to be replaced by a parameter.
- Do one of the following:
- Press Ctrl+Alt+P.
- Choose Refactor | Extract | Parameter on the main menu or on the context menu.
- If more than one expression is detected for the current cursor position, the Expressions list appears. If this is the case, select the required expression. To do that, click the expression. Alternatively, use the Up and Down arrow keys to navigate to the expression of interest, and then press Enter to select it.
- In the:
- Specify the parameter name in the Name field.
- If more than one occurrence of the expression is found within the function body, you can choose to replace only the selected occurrence or all the found occurrences with the references to the new parameter. Use the Replace all occurrences checkbox to specify your intention.
- Preview and apply changes.
Last modified: 15 December 2017