Change signature
The Change Signature refactoring combines several different modifications that can be applied to a function, method, or a method specification. You can use this refactoring to:
change the method/function name
add, remove, and reorder parameters
assign default values to new non-variadic parameters
When changing a method/function signature, GoLand 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. When you refactor a method specification, you will see a notification dialog where you can select to update all implementations as well.
Change a method or function signature
Click a method/function name that you want to refactor.
Press Ctrl+F6. Alternatively, select
from the main menu or from the context menu.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.
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 and specify the properties of the new parameter in the corresponding table row.
To remove a parameter, select any row and click .
To reorder the parameters, use the Up () and Down () icons.
Reuse types simplifies the process of declaring multiple variables of the same type. When you enable this option, the IDE automatically groups variables of the same type together in your declaration.
For example, instead of
firstName string, lastName string, age int, id int
, the IDE will transform the code tofirstName, lastName string, age, id int
.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).
Click Refactor.
Add a return value
Click the function name and press Ctrl+F6. Alternatively, select
from the main menu or from the context menu.In the Change Signature dialog, click the Result parameters tab and click the Add icon ().
In the Type text field, specify the return value.
Click Refactor.
Add parameters
Click the
return
value that is highlighted in red color.Press Alt+Enter and select Create parameter '<parameter_name>'.
In the Change Signature dialog, adjust parameter settings or accept suggested settings.
Click Refactor.
Productivity tips
Add missing parameters
Click a parameter in the signature, press Alt+Enter and select the Change signature refactoring. See the demo1.go file in the GitHub repository.
Change the parameter type
Click a parameter in the signature, press Alt+Enter and select the Change signature refactoring. See the demo1.go file in the GitHub repository.
Change function parameters
You can automatically infer and add a parameter to the function call or add missing return parameters in a signature.
Change signature dialog
The Change Signature refactoring combines several different modifications that can be applied to a function, method, or a method specification. You can use this refactoring to:
change the method/function name
add, remove, and reorder parameters
assign default values to new non-variadic parameters
When changing a method/function signature, GoLand 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. When you refactor a method specification, you will see a notification dialog where you can select to update all implementations as well.
Item | Description |
---|---|
Name | Name of a function, method, or a method specification. |
Parameters | List of parameters in the signature. In the Parameters field, you can perform the following actions with parameters:
|
Result parameters | Returned or result parameters of a Go function. You can specify properties of the new parameter in the corresponding table row (a name, type, and a default value). |