Home

 

Refactoring

During the development of a Java application, it might be necessary to perform tasks, such as renaming classes, moving classes between packages, and breaking out code into separate methods. Such tasks are both time consuming and error prone, because it is up to the programmer to find and update each and every reference throughout the project code. Application Developer provides a list of refactor actions to automate the this process.

The Java development tools (JDT) of Application Developer provide assistance for managing refactoring. In each refactor wizard, you can select:

Refactor with preview: Click Next in the dialog to bring up a second dialog panel where you are notified of potential problems and are given a detailed preview of what the refactor action will do.

Refactor without preview: Click Finish in the dialog and have the refactor performed. If a stop problem is detected, refactor cancels and a list of problems is displayed.

Table | -10 provides a summary of common refactor actions.

Table 8-10

Name Function
Rename Starts the Rename Compilation Unit wizard. Renames the selected element and (if enabled) corrects all references to the elements (also in other files). It 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. Right-click the element and select Refactor Æ Rename, or select the element and press Alt+Shift+R, or select Refactor Æ Rename from the menu bar.
Move Starts the Move 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. Right-click the method signature and select Refactor Æ Move, or select the method signature and press Alt+Shift+V, or select Refactor Æ Move from the menu bar.
Change Method Signature Starts the Change Method Signature wizard. You can change the visibility of the method, change parameter names, parameter order, parameter types, add parameters, and change return types. The wizard updates all references to the changed method. Right-click the element and select Refactor Æ Change Method Signature, or select the element and press Alt+Shift+C, or select Refactor Æ Change Method Signature from the menu bar.
Extract Interface Starts the Extract Interface wizard. You can create an interface from a set of methods and make the selected class implements the newly created interface. Right-click the class and select Refactor Æ Extract Interface, or select the element and select Refactor Æ Extract Interface from the menu bar.
Push Down Starts the Push Down wizard. Moves a field or method to its subclasses. Can be applied to one or more methods from the same type or on a text selection resolving to a field or method. Right-click the type and select Refactor Æ Push Down, or select the element and select Refactor Æ Push Down from the menu bar.
Pull Up Starts the Pull Up wizard. Moves a field or method to its superclass. 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. Right-click the type and select Refactor Æ Push Up, or select the element and select Refactor Æ Push Up from the menu bar.
Extract Method Starts the Extract Method wizard. Creates a new method containing the statements or expressions currently selected, and replaces the selection with a reference to the new method. Right-click the statement or expression and select Refactor Æ Extract Method, or select it and press Alt+Shift+M, or select Refactor Æ Extract Method from the menu bar.
Extract Local Variable Starts the Extract Local Variable wizard. Creates a new variable assigned to the expression currently selected and replaces the selection with a reference to the new variable. Right-click the expression and select Refactor Æ Extract Local Variable, or select it and press Alt+Shift+L, or select Refactor Æ Extract Local Variable from the menu bar.
Extract Constant Starts the Extract Constant wizard. Creates a static final field from the selected expression and substitutes a field reference, and optionally replaces all other places where the same expression occurs. Right-click the expression and select Refactor Æ Extract Constant, or select Refactor Æ Extract Constant from the menu bar.
Inline Starts the Inline Method wizard. Inlines local variables, non-abstract methods, or static final fields. Right-click the element and select Refactor Æ Inline, or select the element and press Alt+Shift+I, or select Refactor Æ Inline from the menu bar.
Encapsulate Field Starts the Encapsulate Field wizard. Replaces all references to a field with getter and setter methods. Is applicable to a selected field or a text selection resolving to a field. Right-click the field, and select Refactor Æ Encapsulate Field..., or select the element and select Refactor Æ Encapsulate Field... from the menu bar.

Refactor actions

ibm.com/redbooks