IntelliJ IDEA 2016.2 Help

Change Signature Dialog for Java

Refactor | Change Signature
Ctrl+F6

Use the Change Signature dialog to perform the Change Method Signature in Java refactoring.

Use the available controls to make changes to the method signature. Specify how the method calls should be handled. Optionally, select the calling methods that the added parameters and exceptions (if any) should be propagated to.

Click Refactor to perform the refactoring right away. Click Preview to see the potential changes prior to actually performing the refactoring. (These will be shown in the Find tool window.)

ItemDescription
VisibilitySelect the method visibility scope (access level modifier) from the list.
Return typeUse this field to modify the method return type.

Code completion (Ctrl+Space) is available in this field, and also in other fields used for specifying the types.

NameUse this field to modify the method name.
ParametersSee the description of the Parameters tab.
ExceptionsSee the description of the Exceptions tab.
Method callsSelect one of the following options to specify how the method calls should be handled:
  • Modify. The existing method calls are modified so that the method with the new signature is called.
  • Delegate via overloading method. The existing method calls don't change. A new overloading method with the old signature is created. This new method calls the method with the new signature.
Signature PreviewIn this area, the current method signature is shown. (The information in this area is synchronized with the changes you are making to the method signature.)

Parameters tab

Use the Parameters tab to manage the method parameters.

The available controls let you add new parameters, remove the existing ones, reorder the parameters and also propagate new parameters to the calling methods (see the descriptions that follow).

In addition to that, you can change the type and name for the existing parameters.

To start editing a parameter, just click it. Alternatively, use the Up and Down arrow keys to move to the parameter of interest and Enter to start modifying it.

ItemTooltip and shortcutDescription
add Add
Alt+Insert
Use this icon or shortcut to start adding a new parameter.

Specify the type, name, and default value in the corresponding fields. (The default parameter value is the value (or the expression) to be passed to the method in the method calls.)

If necessary, select the Use Any Var option. As a result, IntelliJ IDEA will search for a variable of the corresponding type near the method call. If such a variable is found, it will be placed in the method call instead of the default value.

If more than one variable is found, or the Use Any Var option is not selected, IntelliJ IDEA will use the default value in the call.

You can also propagate the parameters you have added to the calling methods.

delete Remove
Alt+Delete
Use this icon or shortcut to delete the selected parameter.
arrowUp Up
Alt+Up
Use this icon or shortcut to move the selected parameter one line up in the list of parameters.
arrowDown Down
Alt+Down
Use this icon or shortcut to move the selected parameter one line down in the list of parameters.
propagateParameters Propagate Parameters
Alt+G
Use this icon or shortcut to propagate the added parameters to the calling methods.

You can propagate the changes made to the method parameters to any method that directly or indirectly calls the method whose signature you are changing.

(There may be the methods that call the current method. These, in their turn, may be called by other methods. You can propagate the changes to any of the methods in such sequences.)

In the dialog that opens, select the methods you want the changes to be propagated to.

Note that only the selected calling methods and the method calls within them will be affected. That is, the default values will be added into other method calls.

Create and initialize class properties The check box is available only in the PHP context when the Change signature refactoring is invoked from the constructor of a class.
  • When this check box is selected and you add a parameter, this parameter is initialized as a field. IntelliJ IDEA creates a protected field with the same name as this parameter and adds a line with the following assignment: $this-><parameter_name> = $<parameter_name>;
  • When the check box is cleared, a parameter is added without initialization.

For example, you have the following constructor:

class ChangeSignatureNewParam { function __construct() { $a = "Constructor in ChangeSignatureNewParam"; print $a; } }
If you invoke the Change signature refactoring from the __construct() method and add a new $q parameter, the result will depend on whether you select or clear the Create and initialize class properties check box:

The Create and initialize class properties check box is selected The Create and initialize class properties check box is cleared
class ChangeSignatureNewParam { private $q; function __construct( $q ) { $a = "Constructor in ChangeSignatureNewParam"; print $a; $this->q = $q; } }
class ChangeSignatureNewParam { function __construct( $q ) { $a = "Constructor in ChangeSignatureNewParam"; print $a; } }

Exceptions tab

Use the Exceptions tab to manage the exceptions thrown by the method.

The available controls let you add new exceptions, remove the existing ones, reorder the exceptions and also propagate new exceptions to the calling methods (see the descriptions that follow).

In addition to that, you can edit the existing exceptions.

To start editing an exception, just click it.

ItemDescription
add or Alt+Insert Use this icon or shortcut to add a new exception.

Start typing in the field and then select the required exception type from the suggestion list.

Note that you can propagate the exceptions you have added to the calling methods.

delete or Alt+DeleteUse this icon or shortcut to delete the selected exception.
arrowUp or Alt+UpUse this icon or shortcut to move the selected exception one line up in the list of exceptions.
arrowDown or Alt+DownUse this icon or shortcut to move the selected exception one line down in the list of exceptions.
propagateParameters or Alt+XUse this icon or shortcut to propagate the added exceptions to the calling methods.

You can propagate the exceptions you have added to any method that directly or indirectly calls the method whose signature you are changing.

(There may be the methods that call the current method. These methods, in their turn, may be called by other methods. You can propagate the changes to any of the methods in such sequences.)

In the dialog that opens, select the methods you want the exceptions to be propagated to.

See Also

Last modified: 23 November 2016