Extract Method Refactoring Specification
$Id: extractmethod.html,v 1.7 2005/08/11 14:03:45 jbecicka Exp $ (see
full
CVS
history)
Refactoring feature that allows to turn a selected code fragment
into a method.
Implementation of this refactoring is tracked in issue
57719.
Pre-Conditions
- A block of statements or an expression is selected.
Pre-Checks
- [4.2] Error: The selection is analyzed and checked if there is at most
one output parameter.
- [4.2] Error: The selection is checked if it does not contain a break
statement
for which the correspondent break target is not part of the selection.
- Error: The selection is checked if it does not contain a continue
statement
for which the correspondent continue target is not part of the
selection.
- [4.2] Error: The selection is checked if it does not contain a return
statement that is not the last statement of the selection (i.e. the
selected code is not allowed to return conditionally).
Parameters
- Name of the new method.
- Modifiers of the method (visibility, static modifier).
- Names of the method parameters (parameters correspond to the
inputs into the selection)
- Order of the method parameters.
Fast Parameters Check
No specific checks.
Parameters Check
- Error: The entered method name causes ambiguities in the class.
- Warning: The new method overrides or is overridden.
Changes To Be Made
- The extracted method is added in the class.
- The selection is replaced by a method call. If a return statement
is the last statement of the selection, the selection is replaced by a
return statement that contains the method call as its argument.
Checks During Changes Preparation
No specific checks.
Refactoring UI
Menu item:
Extract Method...
Action title:
Extract Method - Selection
The panel should display a text field for entering the method name, a
checkbox for selecting whether to declare the method as static or not,
a combo for selecting the visibility modifier of the method, a
list box containing the method parameters (where each parameter name should be editable
- editable parameters will not be implemented for 4.2) and two buttons (Move up and Move down) allowing to change
order of the method parameters.
----------------------------------------------------------
| ----------------------------------------- |
| Method Name: | newMethod | |
| ----------------------------------------- |
| ____________ |
| Access: | public [v]| |
| ------------ |
| |X| Declare static |
| |
| Method Parameters: |
| --------------------------------------- ------------- |
| | Name | Type | | Move Up | |
| |-------------------------------------| ------------- |
| | param_1 | int | ------------- |
| | param_2 | char | | Move Down | |
| | | | ------------- |
| --------------------------------------- |
| |
| +-Method Signature Preview--------------------------+ |
| | public static void newMethod(int par1, char par2) | |
| +---------------------------------------------------+ |
----------------------------------------------------------