【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

    image

  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.
    工作台会分析并展示由于重命名该资源而导致的更改预览。
    重命名一个编译单元会导致其他编译单元导入语句的变化,这些也会显示在预览面板中。

    image

  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
     

    image

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

转载于:https://my.oschina.net/ywlaker/blog/475270

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值