cornercorner
FeaturesPluginsDocs & SupportCommunityPartners

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

  1. A block of statements or an expression is selected.

Pre-Checks

  1. [4.2] Error: The selection is analyzed and checked if there is at most one output parameter.
  2. [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.
  3. 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. [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

  1. Name of the new method.
  2. Modifiers of the method (visibility, static modifier).
  3. Names of the method parameters (parameters correspond to the inputs into the selection)
  4. Order of the method parameters.

Fast Parameters Check

No specific checks.

Parameters Check

  1. Error: The entered method name causes ambiguities in the class.
  2. Warning: The new method overrides or is overridden.

Changes To Be Made

  1. The extracted method is added in the class.
  2. 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) |  |
| +---------------------------------------------------+  |
----------------------------------------------------------
Companion
Projects:
MySQL Database Server   GlassFish Community: an Open Source Application Server   Open Solaris  Open JDK: an Open SourceJDK   Mobile & Embedded Community     Sponsored by 
Sponsored by Sun Microsystems