Kinds of Refactoring Actions
Depending on the context from which you choose to refactor, various refactoring commands are available.
Refactoring Commands
Context
|
Available Refactoring Commands
|
Package
|
Rename
|
Class
|
Rename
Move to another package
|
Method
|
Rename
Rename parameters
|
Code
|
Extract Method
|
Rename Element
You can rename an element, and the workbench's refactoring support changes both the selected resource's name and all references to it.
-
Package
: Updates all import statements of any affected compilation units.
-
Compilation Unit
: Renaming a compilation unit will also rename (and update all references to) the top-level type that has the same name as the compilation unit. For example, renaming a compilation unit
A.java
in which a class
A
is declared will also rename class
A
and update all references to it.
-
Class, Field, Or Interface
: You can rename a class, field, or interface by modifying its declaration in the compilation unit in which it is declared. You can also update all references to the class, field, or interface.
-
Method
: Renaming a method declared in an interface will also rename (and update all references to) all methods that are abstract and non-abstract implementations of that method. All such methods in all subclasses of the interface in which the method is declared will be renamed.
-
When renaming a non-static method declared as public, package visible, or protected, all methods overriding it will also be renamed and all references to them updated.
-
Renaming a static method or a private method will update references only to that method, since it cannot be overridden.
-
You can rename a method by modifying its declaration in the compilation unit in which it is declared. You can also update all references to the method.
Rename Method Parameters
You can rename the parameters of a method by renaming the parameter's declaration as well as all references to the parameters inside the method
body. Use the
Rename Parameters
command to rename the parameters of a method as well as all references to these parameters.
Move Compilation Unit
You can move a compilation unit to a different package. Imports and references are automatically updated.
Extract Method
When you extract a method, the workbench removes a fragment of code from an existing method body and creates a new method for it, also adding a call from the old method to the new method. This feature is useful for cleaning up lengthy, cluttered, or overly-complicated methods.