Replace Method Code Duplicates Refactoring Specification
$Id: replacemethodduplicates.html,v 1.3 2005/04/19 12:00:59 dprusa Exp $ (see
full
CVS
history)
Refactoring feature that allows to locate selected method code
repetitions and turn them into the method call.
Implementation of this refactoring is tracked in issue
57715.
Pre-Conditions
- A method is selected.
Pre-Checks
No specific checks.
Parameters
No parameters.
Fast Parameters Check
No specific checks.
Parameters Check
No specific checks.
Changes To Be Made
- Detected repetitions of the selected method code are turned into
the method call. These changes are driven by the following rules:
- Only the class the method resides in and all its nested classes
are searched for the repetitions of the method code (e.g. if the method
is declared in an anonymous inner class, we
search for duplicates within the scope of the anonymous class only).
- If the selected method is an instance method, we search for the
code duplicates in instance methods only.
- A block of statements is a duplicate of the selected method
body if and only if the statements match exactly the statements in the
method body (one by one), except the following two cases:
- names of local varibles are not required to match, it is
sufficient if there is a proper correspondence among local variables
and their usages in both blocks of statements
- counterparts to the method parameters used in the method body
are expressions - for a particular parameter, all its usages in the
method body must correspond to usages of (the same) expression in the
block of statements
- The created method call contains parameters (if there are any)
that correspond to the expressions described in the previous point.
- If the method return type differs to void, the code duplicate
is replaced by return statement which returns value returned by the
method call.
Checks During Changes Preparation
No specific checks.
Refactoring UI
No specific refactoring UI.