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
- 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 Next.
- The workbench analyzes the proposed change and presents you with a preview
of the changes that would take place if you rename this
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
- 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 Finish 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 Compilation Unit.
- 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.