FeaturesPluginsDocs & SupportCommunityPartners

Move Method Refactoring Specification

$Id: movemethod.html,v 1.5 2005/06/07 14:59:42 jbecicka Exp $ (see full CVS history)

Refactoring feature that allows to move a static method to another class or an instance method to one of the method's parameter types.
Implementation of this refactoring is tracked in issue 57767.

Pre-Conditions

  1. A method is selected.

Pre-Checks

  1. An instance method that does not have any class type parameter is selected.

Parameters

  1. Target class (for static method) or one of the class types of the method parameters (for instance method).
  2. Name of the method.
  3. Modifiers of the method.
  4. Name of the new parameter which is added in the case of an instance method.

Fast Parameters Check

  1. Name of the new parameter clashes with one of the other parameter names.

Parameters Check

  1. Fatal: Check if the moved method will not cause ambiguities in the target.
  2. Non-fatal: Check if all members the method accesses will be vissible after it is moved.
  3. Non-fatal: Check if the method is visible after it is moved for all its usages.
  4. Non-fatal: Check whether the moved method does not override or is not overriden.

Changes To Be Made

  1. If the method is static it is moved into the target class. References to the method are updated accordingly.
  2. If the method is instance (and thus moved into parameter type), the method parameter corresponding to the selected target is removed (in the method body, it is replaced by "this") and a new parameter is added - its type equals the original class. The original method is changed to delegate on the new method.

Checks During Changes Preparation


No specific checks.

Refactoring UI

Menu item: Move Method...
Action title: Move Method - method_name

If a static method is selected, the panel should display a label with name of the selected class, a text field for name of the target (it can be optionally chosen in browser which is invoked by Browse button) and a combo for selecting the visibility modifier. If an instance method is selected, the target class is chosen from a combo of parameter types that are classes. There is also an additional text field for entering name of the new method parameter.
Schemas of panels for a static and instance method follow.

-----------------------------------------
| Move from:  pkg.OriginalClass         |
|             -------------------       |
| Move to:    | pkg.TargetClass | [...] |
|             -------------------       |
|              _________________        |
| Access:     | public       [v]|       |
|             |-----------------|       |
--------------| protected       |--------
              | <default>       |
              | private         |
              -------------------
-----------------------------------------
| Move from:      pkg.OriginalClass     |
|                 --------------------| |
| Move to:        | ParamType_1   [v] | |
|                 --------------------- |
|                 --------------------- |
| Parameter Name: | paramName         | |       
|                 --------------------- |
|                  ___________________  |
| Access:         | public         [v]| |
|                 |-------------------| |
------------------| protected         |--
                  | <default>         |
                  | private           |
                  ---------------------
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by