Declare Field with Initializer
- 2 min to read
Generates a field of the appropriate type for the selected parameter. This Code Provider is useful for Test-Driven Development. It allows you to easily create declarations for fields referenced in a code fragment.
Available when the caret is on a method parameter within the method declaration.
Place the caret on an undeclared parameter.
Hit Ctrl + . or Ctrl + ~ to invoke the Code Actions Menu.
Use the mouse to select Declare | Declare Field with Initializer from the menu and press Enter. The red target picker marker appears. It allows you to choose the place where the generated code can be inserted.
Use the Up Arrow and Down Arrow keys to move the target picker.
Press Enter to generate a code in the selected place.
After execution, the Code Provider adds the initialized field declaration to the current class and assigns the parameter value to it.
The following screencast shows the described steps in action.
You can configure the Target Picker on the Editor | All Languages | Code Actions | Target Picker options page.