FeaturesPluginsDocs & SupportCommunityPartners

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

  1. An expression is selected.

Pre-Checks

  1. [4.2] Error: The selected expression is not in a method body scope.

Parameters

  1. Name of the new local variable.
  2. Type of the new variable (if the expression is e.g. a number and there are more possibilities how to choose type).
  3. 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).
  4. Modifiers of the new local variable - whether it should be final or not.

Fast Parameters Check


No checks here.

Parameters Check

  1. Error: There is already a local variable with the entered name.
  2. 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

  1. 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.
  2. 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                    |
----------------------------------------
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