Introduce Variable Refactoring Specification
$Id: introducevariable.html,v 1.5 2005/08/11 09:06:51 jbecicka Exp $ (see
full
CVS
history)
Refactoring feature that allows to replace occurences of an
expression (in a method scope) by a new local variable, which is
initialized by the expression.
Implementation of this refactoring is tracked in issue
57522.
Pre-Conditions
- An expression is selected.
Pre-Checks
- [4.2] Error: The selected expression is not in a method body scope.
Parameters
- Name of the new local variable.
- Type of the new variable (if the expression is e.g. a number and
there are more possibilities how to choose type).
- Boolean flag indicating whether all occurrences of the expression
in the correspondent scope should be replaced by the variable or not
(in the latter case, only the selected expression is replaced).
- Modifiers of the new local variable - whether it should be final
or not.
Fast Parameters Check
No checks here.
Parameters Check
- Error: There is already a local variable with the entered name.
- Error: The new local variable is named as one of the class fields
and the field is accessed in the correspondent scope.
Changes To Be Made
- Add the new local variable into the related method, make it to be
initialized by the selected expression. Declaration of the new local
variable must precede its usages.
- Replace one or all occurrences of the expression (depending on
the third parameter) in the scope. Note that invocations of the same
method with the same parameters (as well as instantiation of a class
using the same constructor) are cosidered as the same expressions. If
the user does not want to replace all these calls by the local variable
initialized by one call, he selects the appropriate value for the third
parameter.
Checks During Changes Preparation
No specific checks.
Refactoring UI
Menu item:
Introduce Variable...
Action title:
Introduce Variable - selection
The panel should display a combo-box for selecting a type of the
variable (only if there are more possibilites, otherwise this value is
predefined and displayed using a label), a text field for entering name
of the variable, a checkbox for selecting whether all occurences of the
expression should be replaced (it is displayed only if there are more
than one occurrences of the expression) and a checkbox for selecting
wheter the local variable should be declared as final.
----------------------------------------
| ------------------------- |
| Name: | i | |
| ------------------------- |
| ------------------------- |
| Type: | int |v| |
| ------------------------- |
| [ ] Replace All Occurrences |
| [ ] Declare final |
----------------------------------------