【Eclipse】使用指南(22)执行代码片段

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

Evaluating snippets

计算片段

In this section, you will evaluate Java expressions using the Java scrapbook. Java scrapbook pages allow you to experiment with Java code fragments before putting them in your program.
本小节,你将学会使用Java剪贴板测试将要放入程序中的Java代码片段。

  1. In the File menu select New > Other > Java > Java Run/Debug > Scrapbook Page. You will be prompted for a folder destination for the page.
    选择New > Other > Java > Java Run/Debug > Scrapbook Page菜单。弹出如下对话框
    【Eclipse】使用指南(22)执行代码片段_第1张图片
    点击NEXT后弹出如下提示框

    【Eclipse】使用指南(22)执行代码片段_第2张图片

  2. In the Enter or select the folder field, type or browse below to select the JUnit project root directory.
    Enter or select the folder输入框中输入并选择JUnit 工程的根目录。
  3. In the File name field, type MyScrap
    File name输入框中输入MyScrap
  4. Click Finish when you are done.  A scrapbook page resource is created for you with the jpage file extension.  (The jpage file extension will be added automatically if you do not enter it yourself.)  The scrapbook page opens automatically in an editor.
    点击完成,创建scrapbook page成功。
  5. In the editor, typeSystem.getand then use content assist (Ctrl+Space) to complete the snippet asSystem.getProperties().
    在编辑器中输入System.get,然后使用内容助手完成System.getProperties()。

    【Eclipse】使用指南(22)执行代码片段_第3张图片

  6. Select the entire line you just typed and select Display from the context menu.  You can also select Display Result of Evaluating Selected Text from the toolbar.
    选中整行,右键选择Display 菜单,也可以使用快捷工具栏中的Display Result of Evaluating Selected Text 按钮。
    【Eclipse】使用指南(22)执行代码片段_第4张图片

    【Eclipse】使用指南(22)执行代码片段_第5张图片

  7. When the evaluation completes, the result of the evaluation is displayed and highlighted in the scrapbook page.
    运行完,计算结果会显示出来。
  8. You can inspect the result of an evaluation by selecting text and choosing Inspect from the context menu (or selecting Inspect Result of Evaluating Selected Text from the toolbar.)
  9. When you are finished evaluating code snippets in the scrapbook page, you can close the editor.  Save the changes in the page if you want to keep the snippets for future use.
    完成操作,可以保存以备后用。

你可能感兴趣的:(java,page,scrapbook)