AppCode 2018.3 Help

Change signature

The Change Signature refactoring combines several different modifications that can be applied to a method/function signature. You can use this refactoring for the following purposes:

  • To change the method/function name.

  • To change the method/function return type.

  • To add new parameters and remove the existing ones.

  • To assign default values to the parameters.

  • To reorder parameters.

  • To change parameter names and types.

When changing a method/function signature, AppCode searches for all usages of the method/function and updates all the calls, implementations, and override replacements of the method/function that can be safely modified to reflect the change.

More refactoring examples

To see how different refactoring settings discussed above affect the refactoring result, let us consider the following examples.

All the examples are a simplified version of the refactoring shown earlier. In all cases, a new parameter wireframe1 of the type Boolean is added to the function paint() defined in the IShape interface.

In different examples, different combinations of the initializer and the default value are used, and the new parameter is either propagated to Canvas.paint() (which calls IShape.paint()) or not.

Initializer

Default value

Propagation used

Result

false

Yes

public interface IShape { function paint(g:Graphics, wireframe:Boolean):void; } // The function paint() in the Canvas class: public function paint(g:Graphics, wireframe:Boolean): void { for each ( var shape: IShape in shapes) { shape.paint(g,wireframe); } }

false

No

public interface IShape { function paint(g:Graphics, wireframe:Boolean):void; } // The function paint() in the Canvas class: public function paint(g:Graphics): void { for each ( var shape: IShape in shapes) { shape.paint(g,false); } }

true

Yes

public interface IShape { function paint(g:Graphics, wireframe:Boolean = true):void; } // The function paint() in the Canvas class: public function paint(g:Graphics): void { for each ( var shape: IShape in shapes) { shape.paint(g); } }

true

No

public interface IShape { function paint(g:Graphics, wireframe:Boolean = true):void; } // The function paint() in the Canvas class: public function paint(g:Graphics):void { for each ( var shape: IShape in shapes) { shape.paint(g); } }

true

false

Yes

public interface IShape { function paint(g:Graphics, wireframe:Boolean = true):void; } // The function paint() in the Canvas class: public function paint(g:Graphics, wireframe:Boolean = true): void { for each ( var shape: IShape in shapes) { shape.paint(g,wireframe); } }

true

false

No

public interface IShape { function paint(g:Graphics, wireframe:Boolean = true):void; } // The function paint() in the Canvas class: public function paint(g:Graphics): void { for each ( var shape: IShape in shapes) { shape.paint(g,false); } }

Changing a method/function signature

  1. Place a caret on a method/function name that you want to refactor.

  2. Press ⌘F6. Alternatively, select Refactor | Change Signature from the main menu or from the context menu.

  3. In the Change Signature dialog, make the necessary changes to the method/function signature depending on your needs:

    • Change the method/function name. To change the name, edit the text in the Name field.

    • Change the method/function return type by editing the contents of the Return type field.

      You can configure the quotes style for generated import statements on the Punctuation tab of the (AppCode | Preferences | Editor | Code style | TypeScript | Punctuation) page.

    • Manage the method/function parameters. To configure the parameters, use the table and the buttons in the Parameters area:

      • To add a new parameter, click The Add button and specify the properties of the new parameter in the corresponding table row.

      • To remove a parameter, select any row and click The Remove button.

      • To reorder the parameters, use the Up (The Up icon) and Down (The down icon) icons. For example, if you want to put a certain parameter first in the list, click any of the cells in the row corresponding to that parameter, and then click The Up icon the required number of times.

      • To change the name or the default value of a parameter, make the necessary updates in the table of parameters (in the fields Name and Default value respectively).

  4. Click Refactor.

    Change signature refactoring
Last modified: 28 March 2019