Skip to main content
A newer version of this page is available. .

Declare Field with Initializer

  • 2 minutes to read

Purpose

Generates a field of the appropriate type for the selected parameter. You can use this code provider for Test-Driven Development. It allows you to easily create declarations for fields referenced in a code fragment.

Availability

Available when the caret is in a method parameter within the method declaration.

Usage

  1. Place the caret in an undeclared parameter.

  2. Press Ctrl + . or Ctrl + ~ to invoke the Code Actions menu.

  3. Use the mouse to select 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.

  4. Use the Up Arrow and Down Arrow keys to move the target picker.

  5. Press Enter to generate a code in the selected place.

After execution, this 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.

DeclareFieldWith

You can configure the Target Picker on the Editor | All Languages | Code Actions | Target Picker options page.

TargetPicker

NOTE

The default visibility modifier of the generated member is configured on the Editor | <Language> | Scope Options options page. Refer to the Scope topic for details.