CLion 2018.2 Help

Change Signature

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

  • To change the function name.

  • To change the function return type.

  • To add new parameters and remove the existing ones.

  • To reorder parameters.

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


The following tables show possible ways of performing the Change Signature refactoring for code in different languages.



//Initial function signature int exFunction2(int a, int b) { int x = a+b; return x; }; int main() { int a = 0, b = 1; int x = exFunction2(a, b); return 0; }

//Name changed, the third parameter introduced int exFunction3(int a, int b, int c) { int x = a+b; return x; }; int main() { int a = 0, b = 1; int x = exFunction3(a, b, 0); //default value '0' added return 0; }



//This function will be turned into a block float multiply (int x, int y) { return x * y; } int main (int argc, const char * argv[]) { @autoreleasepool { float result; result = multiply( 10, 20 ); } return 0; }

int main (int argc, const char * argv[]) { @autoreleasepool { float result; result = //a block was generated ^float(int x, int y) { return x * y; }(10, 20); } return 0; }



# This function will be renamed def fibonacci( n ): a, b = 0, 1 while b < n: print( b ) a, b = b, a+b n = int(input("n = ")) fibonacci( n )

# Function with the new name def fibonacci_numbers( n ): a, b = 0, 1 while b < n: print( b ) a, b = b, a+b n = int(input("n = ")) fibonacci_numbers( n )



//This function wil be renamed //and a default parameter will be added function result() { } function show_result() { alert('Result: ' + result()); }

//Function with a new name and default parameter function generate_result(input = 100) { } function show_result() { alert('Result: ' + generate_result()); }

Changing a function signature

  1. In the editor, place the cursor within the name of the function whose signature you want to change.

  2. Do one of the following:
    • Press Ctrl+F6.

    • Choose Refactor | Change Signature on the main menu or context menu.

  3. In the Change Signature dialog, make the necessary changes to the function signature and specify what other, related, changes are required.

    You can:

    • Change the function name. To do that, edit the text in the Name field.

    • Manage the function parameters using the table and the buttons in the Parameters area:
      • To add a new parameter, click icons general add svg and specify the properties of the new parameter in the corresponding table row.

      • To remove a parameter, click any of the cells in the corresponding row, and then click icons general remove svg.

      • To reorder the parameters, use the icons actions previousOccurence svg and icons actions nextOccurence svg buttons. 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 icons actions previousOccurence svg the required number of times.

  4. To perform the refactoring right away, click Refactor.

    To see the expected changes and make the necessary adjustments prior to actually performing the refactoring, click Preview.

    cl refactoring dialog
Last modified: 27 November 2018

See Also

External Links: