The goal of Java program refactoring is to make system-wide code changes without affecting the behavior of the program. The Java tools provide assistance in easily refactoring code.
The refactoring tools support a number of transformations described in Martin Fowler's book 'Refactoring: Improving the Design of Existing Code', Addison Wesley 1999, such as Extract Method, Inline Local Variable, etc.
When performing a refactoring operation, you can optionally preview all of the changes resulting from a refactoring action before you choose to carry them out. When previewing a refactoring operation, you will be notified of potential problems and will be presented with a list of the changes the refactoring action will perform. If you do not preview a refactoring operation, the change will be made in its entirety and any resultant problems will be shown. If a problem is detected that does not allow the refactoring to continue, the operation will be halted and a list of problems will be displayed.
Refactoring commands are available from the context menus of several Java views (e.g. Package Explorer, Outline) and editors. Many "apparently simple" commands, such as Move and Rename, are actually refactoring operations, since moving and renaming Java elements often require changes in dependent files.
Refactor menu commands:
Does an Undo of the last refactoring. The refactoring undo buffer is only valid as long as no other source changes than refactoring have been performed.
Does a Redo of the last undone refactoring. The refactoring undo/redo buffer is only valid as long as no other source changes than refactoring have been performed.
Starts the Rename refactoring dialog: 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.
Starts the Move refactoring dialog: Moves the selected elements and (if enabled) corrects all references to the elements (also in other files). Can be applied to one instance method (which can be moved to a component), 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.
Change Method Signature
Starts the Change Method Signature refactoring dialog. Changes parameter names, parameter types, parameter order and updates all references to the corresponding method. Additionally, parameters can be removed or added and method return type as well as its visibility can be changed. This refactoring can be applied to methods or on text selection resolving to a method.
Convert Anonymous Class to Nested
Start the Convert Anonymous Class to Nested Class refactoring dialog. Helps you convert an anonymous inner class to a member class. This refactoring can be applied to anonymous inner classes.
Convert Nested Type to Top Level
Starts the Convert Nested Type to Top Level Type refactoring dialog. Creates a new Java compilation unit for the selected member type, updating all references as needed.
For non-static member types, a field is added to allow access to the former enclosing instance. This refactoring can be applied to member types or text resolving to a member type.
Starts the Push Down refactoring dialog. Moves a set of methods and fields from a class to its subclasses. This refactoring can be applied to one or more methods and fields declared in the same type or on a text selection inside a field or method.
Starts the Pull Up refactoring wizard. Moves a field or method to a superclass of its declaring class or (in the case of methods) declares the method as abstract in the superclass. This refactoring can be applied on one or more methods, fields and member types declared in the same type or on a text selection inside a field, method or member type.
Starts the Extract Interface refactoring dialog. Creates a new interface with a set of methods and makes the selected class implement the interface, optionally changing references to the class to the new interface wherever possible. This refactoring can be applied to types.
Use Supertype Where Possible
Starts the Use Supertype Where Possible dialog. Replaces occurrences of a type with one of its supertypes after identifying all places where this replacement is possible.This refactoring is available on types.
Starts the Inline refactoring dialog. Inlines local variables, methods or constants. This refactoring is available on methods, static final fields and text selections that resolve to methods, static final fields or local variables.
Starts the Extract Method refactoring dialog. 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 Local Variable
Starts the Extract Variable refactoring dialog. Creates a new variable assigned to the expression currently selected and replaces the selection with a reference to the new variable. This refactoring is available on text selections that resolve to local variables. You can use Expand Selection to from the Edit menu to get a valid selection range.
Starts the Extract Constant refactoring dialog. Creates a static final field from the selected expression and substitutes a field reference, and optionally rewrites other places where the same expression occurs. This refactoring is available on static final fields and text selections that resolve to static final fields.
Convert Local Variable to Field
Start the Convert Local Variable to Field refactoring dialog. Turn a local variable into a field. If the variable is initialized on creation, then the operation moves the initialization to the new field's declaration or to the class's constructors. This refactoring is available on text selections that resolve to local variables.
Starts the Self Encapsulate Field refactoring dialog. 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.