The requested page is not available for the requested platform. You are viewing the content for Default platform.

Declare Method

  • 2 min to read

Purpose

Generates a method with appropriate parameters for the selected method call. This Code Provider is useful for Test-Driven Development. It allows you to easily create declarations for methods referenced in a code fragment.

Note

A method declared in the interface is automatically added to all its implementers.

Availability

Available when the caret is on the line with an undeclared method.

Usage

  1. Place the caret on an undeclared method's name.

  2. Hit Ctrl + . or Ctrl + ~ to invoke the Code Actions Menu.

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

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

TargetPicker

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

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

After execution, the Code Provider adds the method declaration to the class.

You can configure the default body of newly-generated methods on the Editor | <Language>| Code Actions | Code Actions Settings options page. The default value is "Throw NotImplementedException instance".

CodeActionsSettings

The following screencast shows the described steps in action:

DeclareMethod

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.