Use refactoring features

Refactoring support

The goal of refactoring (behavior-preserving program transformation) is to make a system-wide code change without affecting the behavior of the system. The JDT provides assistance for managing refactorings.

The JDT supports a number of transformations (e.g. Extract Method, Inline Local Variable) described in Martin Fowler's book "Refactoring: Improving the Design of Existing Code", Addison Wesley 1999.

When performing a refactoring operation, you can optionally preview all the impending changes resulting from a refactoring action before you choose to carry them out. Thus, you can execute a refactoring in one of two ways:

Refactoring commands are available from the context menus of several Java views (e.g. Package Explorer, Outline) and editors.

Refactor context menu

Refactor actions

Refactor menu commands:

Refactor menu

Rename

Starts the Rename refactoring wizard: Renames the selected element and (if enabled) corrects all references to the elements (also in other files). Is available on methods, fields, local variables, method parameters, types, compilation units, packages, source folders, projects and on a text selection resolving to one of these element types.

Rename

Rename preview

Move

Starts the Move refactoring wizard: Moves the selected elements and (if enabled) corrects all references to the elements (also in other files). Can be applied on one or more static methods, static fields, types, compilation units, packages, source folders and projects and on a text selection resolving to one of these element types.

Pull Up

Starts the Pull Up refactoring wizard: Moves a field or method to its super class. Can be applied on one or more methods and fields from the same type or on a text selection resolving to a field or method.

Modify Parameters

Starts the Modify Parameters refactoring wizard. Changes parameter names and parameter order and updates all references to the corresponding method. Can be applied on methods with parameters or on text selection resolving to a method with parameters.

Extract Method

Starts the Extract Method refactoring wizard. Creates a new method containing the statements or expression currently selected and replaces the selection with a reference to the new method. You can use Expand Selection to from the Edit menu to get a valid selection range. This feature is useful for cleaning up lengthy, cluttered, or overly-complicated methods.

Extract Variable

Starts the Extract Variable refactoring wizard. Creates a new variable assigned to the expression currently selected and replaces the selection with a reference to the new variable. You can use Expand Selection to from the Edit menu to get a valid selection range.

Inline Local Variable

Starts the Inline Local Variable refactoring wizard. Replaces the references to the selected local variable with the variable's initializer expression and removes the variable.

Self Encapsulate Field

Starts the Self Encapsulate Field refactoring wizard. Replaces all references to a field with getting and setting methods. Is applicable to a selected field or a text selection resolving to a field.

Self Encapsulate Field

Self Encapsulate Field. Preview

Note: Refactoring commands are also available from the context menus in many views and the Java editor.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine