Change Signature
Refactoring with
Change Signature is a convenient way to change the signature of a function, method or member variable. For C/C++, the refactoring changes both declaration and implementation, ensuring the two constructs remain consistent.
Changing signature is useful when a member type, method name, or parameter list becomes unclear or inadequate for meaningful use. The new signature makes a member or method more valuable to developers, and more likely to be used correctly.
You can change signature from an implementation, declaration or reference, allowing you to change without interrupting your normal flow of editing.
Hover over a method and select
Change Signature from the refactoring menu.
A dialog with the current signature opens. Modify the signature to reflect your changes. Make sure your changes maintain proper syntax so
Visual Assist X understands correctly what you intend to change. For example, change the name of a parameter so it is more meaningful.
Accept the new signature and your implementation is changed. For C/C++, the declaration and implementation are both changed so the constructs remain consistent.
If you change the name of a parameter, as in the example, all references to the parameter within the implementation are also changed.
Change Signature of Method
Change Signature on a method permits you to change all parts of a signature including:
- Method name
- Return type
- Visibility
- Parameter names
- Parameter types
- Parameter order
- Number of parameters
- Qualifiers
Changing a method name with
Change Signature causes a dialog to open confirming an appropriate change of all references made to the original name. For example, change
GetIT to
GetItemText.
A dialog opens to confirm rename of references to
GetIT.
Change Signature of Method: Return Type
Changing a return type does not change code accepting return values from references to the method. Instead, you must change all references appropriately to accept the new return type. Use
Find References after
Change Signature to locate the references.
For C/C++, changing return type or qualifiers changes both declaration and implementation.
Change Signature of Method: Parameters
You can change parameter names and types with
Change Signature when invoked from the name of a method, i.e. not from one of the parameters. If you change parameter names,
Visual Assist X assumes your order of parameters remains constant. If you keep parameter names the same, you can reorder them. If you need to change parameter names and parameter order, complete the refactoring by invoking
Change Signature twice - change order in one refactoring and change names in the second.
For example, refactor in two steps to change parameters names and switch order from
c, r to
nRow, nCol. Begin by selecting
Change Signature from the refactoring menu for the method.
Change the parameter names to
nCol and
nRow in the next dialog.
Accept the new signature and your code is changed. Since you renamed a parameter, references to that parameter within the implementation are changed as well.
In a second refactoring of the method, change the parameter order to
nCol and
nRow.
Accept the new signature and you notice the parameter list has changed but nothing within the implementation. Since this is C/C++, changes are made to both declaration and implementation.
Change Signature of Member Variable
In addition to changing signatures of methods, you can change the signature of local variables, member variables and parameters. Such refactoring is done typically from a reference to a variable, and only when the variable needs to be of a different type or visibility.
For C/C++, changing signature of a parameter to a method, not of the method itself, changes only the implementation. The declaration is untouched. Invoke
Change Signature from the name of a method to change both the declaration and implementation.
Change Signature Does Not Change References
Change Signature does not change references to methods or member variables. A warning to this effect may appear if you make a significant change. For example, changing parameter order might require you to rearrange parameters in all references to a method.
Change references manually to accomodate the new signature. Use
Find References after
Change Signature to locate the references.
Miscellaneous
Change Signature is often invoked after
Extract Method.
Change Signature is not available on symbols found using
stable directories, e.g. from MFC or a 3rd party library.
Change Signature is not available on overloaded methods.
Change Signature is also available from the context menu in the
Hovering Class Browser and
VA Outline.
Change Signature does not modify signatures within comments. If signatures exist within comments, you must change them manually.
Use
Change Signature on a method, instead of
Rename, when modifying the name of a method or parameter.
Changing visibility is available only for C#.
Use UNDO to revert changes made to all files by
Change Signature. (One UNDO reverts all changes when using VS2005 or VS.NET. Multiple UNDOs required when using VC++ 6.0.)
You can modify the format of signatures by editing the
VA Snippets entries for
Refactor Create Implementation.