Renaming Java elements
In this section, you will rename a Java element using refactoring.
Refactoring actions change the structure of your code without changing its
semantic behavior.
- In the Package Explorer view, select junit.framework.TestCase.java.
- From its context menu, select Refactor > Rename.
- In the New Name field on the Rename Compilation
Unit page, type "TestCase2".
- To preview the changes that will be made as a result of renaming the
class, press Preview >.
- The workbench analyzes the proposed change and presents you with a preview
of the changes that would take place if you rename this
resource.
Since renaming a compilation unit will affect the import
statements in other compilation units, there are other compilation units
affected by the change. These are shown in a list of changes in the
preview pane.
- On the Refactoring preview page, you can scroll through the proposed
changes and select or deselect changes, if necessary. You will
typically accept all of the proposed changes.
- Click OK to accept all proposed changes.
You have seen that a refactoring action can cause many changes in different
compilation units. These changes can be undone as a group.
- In the menu bar, select Edit > Undo Rename TestCase.java
to TestCase2.java.
- The refactoring changes are undone, and the workbench returns to its previous
state. You can undo refactoring actions right up until you change and save
a compilation unit, at which time the refactoring undo buffer is cleared.
Refactoring support
Refactoring
Renaming a compilation unit
Refactoring without preview
Refactoring with preview
Previewing refactoring changes
Undoing a refactoring operation
Refactoring actions
Refactoring wizard
Java preferences