FeaturesPluginsDocs & SupportCommunityPartners

Inline Method/Variable Refactoring Specification

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

Refactoring feature that allows to "inline" methods, static final fields and local variables.
Implementation of this refactoring is tracked in issue 57545.

Pre-Conditions

  1. One of the following elements is selected: a method, static final field or local variable.

Pre-Checks

  1. Fatal: The selection is not one of the three elements the operation is supported for.
  2. Fatal: Local variable is selected to be inlined, but
    • it has no initializer
    • it is never used in the correspondent scope
    • there is no usage of the variable before the variable is modified
    • when the variable is modified first time, it is also accessed on the right-hand side of the assignment (e.g. a = a*a)

Parameters

  1. If a usage of a method is selected, it has to be specified whether all usages of the correspondent method should be replaced by the inlined code and the method removed or whether just to inline the method for this usage and to keep the method.

Fast Parameters Check


No specific checks.

Parameters Check


No specific checks.

Changes To Be Made

  1. If a method is selected, each usage of the method the operation should be applied on is replaced by the inlined variant of the method. Whenever the method uses local variables of names that clash with names of variables used in the scope of the method usage or with member fields, these local variables are renamed to avoid these clashes. Also, if the method is inlined several times into one method scope, renaming of local variables is required. If the method to inline has parameters, in the inlined code, they are replaced by correspondent passed values. The method is eventually removed, if it has been specified so.
  2. Static final field is inlined into all usages and its declaration is removed.
  3. Usages of local variable are replaced by the value that is assigned into the variable in its initializer. The original declaration of the variable is removed. Replacing continues from the declaration point till an assignment into the variable is found (if there is any). If so, the assignment is changed to the declaration of the (same) local variable, which is initialized by the right-hand side of the assignment.

Checks During Changes Preparation


No specific checks.

Refactoring UI

Menu item: Inline Method...
Action title: Inline Method - method_name
Parameters needs to be specified only if a usage of a method is selected. In such a case, the panel should contain two radio buttons to choose whether to inline the method into all usages or not.
--------------------------------------------------------
| Method method_name(par_1, par_2)                     |
|                                                      |
|  (o) Inline All Invocations and Remove the Method    |
|  ( ) Inline This Invocation Only and Keep the Method |
|                                                      |
-------------------------------------------------------
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