In this section, you will rename a Java element using refactoring.
1. |
In the Packages view, select junit.framework.TestCase.java. |
2. |
From its context menu, select Rename. |
3. |
Renaming is a refactoring action. Refactoring supports changing the structure of your code without changing its semantic behavior. In the Enter New Name field in the Rename Compilation Unit dialog, type " MyTestCase.java ", then click Next. ![]() |
4. |
The workbench analyzes the proposed change and presents you with a preview of the changes that would take place if you actually choose to rename this resource. Renaming a compilation unit invalidates import statements in other compilation units; therefore, a simple rename operation is not sufficient in this case and would result in compile errors. ![]() |
5. |
In the Refactoring preview dialog, you can scroll through the various proposed changes and select or deselect changes, if necessary. Note: Typically, you will accept all the proposed changes. |
6. |
Click Finish to accept all proposed changes. |
7. |
In the Packages view, select the newly-renamed MyTestCase.java file, and from its context menu, select Refactor > Undo Rename TestCase.java to MyTestCase.java. ![]() |
8. |
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 stack is cleared. |