【Eclipse】使用指南(14)重命名Java元素

(翻译说明:http://my.oschina.net/ywlaker/blog/468911)

Renaming Java elements
重命名Java元素

In this section, you will rename a Java element using refactoring.  Refactoring actions change the structure of your code without changing its semantics (behavior).
本小节,你将使用重构来重命名Java元素,重构可以改变代码结构,但保持其行为不变。

  1. In the Package Explorer view, select junit.framework/TestCase.java.
    在包管理器视图中,选择junit.framework/TestCase.java
  2. From its context menu, select Refactor > Rename.
    右键选择Refactor > Rename菜单。
  3. In the New Name field on the Rename Compilation Unit page, type "TestCase2".
    在弹出对话框的New Name输入框中输入TestCase2

    【Eclipse】使用指南(14)重命名Java元素_第1张图片

  4. To preview the changes that will be made as a result of renaming the class, press Next.
    点击Next按钮预览重命名后的影响。
  5. 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.
    工作台会分析并展示由于重命名该资源而导致的更改预览。
    重命名一个编译单元会导致其他编译单元导入语句的变化,这些也会显示在预览面板中。

    【Eclipse】使用指南(14)重命名Java元素_第2张图片

  6. 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.
    在重构预览面板中,你可以滚动来查看并修改更改,通常情况下,你会接受所有更改。
  7. Click Finish to accept all proposed changes.
    点击Finish 按钮接受所有更改。

You have seen that a refactoring action can cause many changes in different compilation units.  These changes can be undone as a group.
如你所见,重构行为会导致大范围的更改,而这些更改可以全部恢复。

  1. In the menu bar, select Edit > Undo Rename Compilation Unit.
    选择菜单栏中的 Edit > Undo Rename Compilation Unit
     

    【Eclipse】使用指南(14)重命名Java元素_第3张图片

  2. 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.
    重构的更改被恢复了,工作台回到了之前的状态。一旦修改了其他编译单元,重构所做更改的缓存就被清除了,所以恢复操作只有这个时间才有效。

你可能感兴趣的:(eclipse,rename)