eclipse 之 scrapbook

[b]eclipse 之 scrapbook[/b]

在日常的编码过程中,经常会遇到一些还不确定功能或性能的方法或者代码片段,如果需要测试这段代码,一般需要单独写一个class类来验证,最近在网上不经意间看到一个可以单独运行代码片段的小工具,使用起来挺方便,故摘录下来,以备参考:

Using Scrapbook Pages
At 6:28 PM on Jan 8, 2006, João Almeida Javalobby Newcomers wrote:

One of the most undervalued and forgotten features of Eclipse is the scrapbook page , which allows to execute Java expressions without having to create a new Java program. This is a neat way to quickly test an existing class or evaluate a code snippet.

To create a scrapbook page choose File -> New -> Other -> Java -> Java Run/Debug -> Scrapbook Page , choose a name and destination folder and that's it. Now there's an empty page where regular Java expressions can be written and evaluated, to do so just select the expression and choose one of the available operations (either in the toolbar now available or the context menu).

Try this: write new java.util.Date() , select the text and click Display or Inspect .

Display will evaluate the expression and print the result directly on the scrapbook, basically the return of a toString() applied to that object or the return value of the selected Java method.

If the information displayed is not enough, there's the Inspect feature (see below) which shows an debug window with all the details of the selected object, and all this happens without executing any code or switching to the Debug perspective.
[img]http://www.eclipsezone.com/admin/forum/servlet/JiveServlet/download/18111-61137-91979999-3706/inspect.png[/img]
To evaluate code snippets there's the Execute feature, this will execute a block of code, just like in a regular java program. A quick way to try this is to send something to the standard output: just write System.out.println("Scrapbook example") , select the text and hit Run , this should print something on the Console window (see below).
[img]http://www.eclipsezone.com/admin/forum/servlet/JiveServlet/download/18111-61137-91979999-3705/run.png[/img]
Because it's created within a Java project a scrapbook page , all the classpath libraries and projects references can be used here; another nice feature is having code assist, just like in a regular Java editor page. In a scrapbook page the class names fully qualified, there's no, this isn't much of a problem because the code completion handles this nicely, but if you're working with unusually large class names you can check the Set Imports option, this will open new window where all the import expressions can be inserted (just the import section of a regular class file).

A scrapbook page is not as fully featured as the Java editor, there's no outline and the code assist is somehow limited, but is not meant to be like that; the idea is working with just a few lines, and this where the scrapbook page can be useful: to quickly test Java expressions and code blocks present in a project in this kind of sandbox.

参考地址:[url]http://www.eclipsezone.com/eclipse/forums/t61137.html[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值