欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

eclipse 之 scrapbook 博客分类: JAVA开发工具web开发学习笔记 eclipsescrapbook 

程序员文章站 2024-03-20 08:33:22
...
eclipse 之 scrapbook

      在日常的编码过程中,经常会遇到一些还不确定功能或性能的方法或者代码片段,如果需要测试这段代码,一般需要单独写一个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.
eclipse 之 scrapbook
            
    
    博客分类: JAVA开发工具web开发学习笔记 eclipsescrapbook 
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).
eclipse 之 scrapbook
            
    
    博客分类: JAVA开发工具web开发学习笔记 eclipsescrapbook 
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.

参考地址:http://www.eclipsezone.com/eclipse/forums/t61137.html
相关标签: eclipse scrapbook