【Eclipse】使用指南(15)移动与复制Java元素

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

Moving and copying Java elements

移动与复制Java元素

In this section, you will use refactoring to move a resource between Java packages.  Refactoring actions change the structure of your code without changing its semantic behavior.
本小节,你将使用重构方法在Java包之间移动资源文件。重构改变代码结构但保持其行为不变。

  1. In the Package Explorer view, select the MyTestCase.java file from the test package and drag it into the junit.samples package. Dragging and dropping the file is similar to selecting the file and choosing Refactor > Move from the context menu.
    在包管理器视图中,选中MyTestCase.java 文件,然后拖动到junit.samples 包中,拖动过程与右键选择Refactor > Move 菜单类似。
  2. You will be prompted to select whether or not to update references to the file you are moving. Typically, you will want to do this to avoid compile errors. You can press the Preview button to see the list of changes that will be made as a result of the move.
    Eclipse会给出提示,是否更新文件的引用,通常情况,你会选择是。可以点击Preview 按钮查看移动文件之后导致的更改列表。
  3. Press OK. The file is moved, and its package declaration changes to reflect the new location.
    点击OK按钮,文件移动了,而且它的包声明也自动更新为当前所在的包。

    【Eclipse】使用指南(15)移动与复制Java元素_第1张图片

  4. Use Edit > Undo Move to undo the move.
    选择Edit > Undo Move菜单回滚操作。

The context menu is an alternative to using drag and drop.  When using the menu, you must specify a target package in the Move dialog, in addition to selecting the update references options you've already seen.
拖拽操作与右键操作功能大体相同,但使用右键菜单时,除更新引用外,还需要指定目标包。

  1. Select the MyTestCase.java file and from its context menu, select Refactor > Move.
    选择MyTestCase.java 文件,右键选择Refactor > Move菜单。
  2. In the Move dialog, expand the hierarchy to browse the possible new locations for the resource. Select the junit.samples package, then click OK. The class is moved, and its package declaration is updated to the new location.
    在弹出的对话框中,展开工程结构,选择junit.samples包,点击OK按钮,文件被移动,它的包声明也被更新了。

    【Eclipse】使用指南(15)移动与复制Java元素_第2张图片

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