开发者

Eclipse plugin for fast java code testing

I wonder if there is a plugin for Eclipse that can execute some java expression?

For example i want to find proper pattern of SimpleDateFormat and i could create new class within which i the开发者_开发问答n initialize several formatters and after compiling and execution i'll see a result, but instead that i want to be able to write those formatters in this plugin view and see their result after execution without new class.

Thanks


I use a scrapbook page.

To create one, go to File -> New -> Other -> Java -> Java Run/Debug -> Scrapbook Page. Type the statements e.g.

String text = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
System.out.println(text);

Execute it, by highlighting the text (Ctrl+A) and then Ctrl+U.

The one thing I don't like, is that it doesn't allow import statements. You have to either type the fully qualified class name as above, or explicitly go into the Set imports menu and add classes you want to import.


You can use an scrapbook page - just select New->Other->Java Run/Debug

In a scrapbook page, you can just write code, then select parts of it and choose "Display", "Inspect" or "Execute" in the context menu.

However, it is actually not very convenient for working with class libraries, because you have to use fully qualified class names.


When you've suspended a running application in debug mode, you can highlight any code fragment and execute it, so that gives you a quick, albeit slightly awkward way of trying out different invocations of SimpleDateFormat. All you need is a single mock class with a main method and a breakpoint in it.


Beanshell allows you to do this. I don't know if there's an eclipse plugin, but you could easily run it standalone, or from within eclipse in the normal way such that it has access to your project classath.

Alternatively when you're in running in debug mode you can evaluate arbitrary expressions in the Display tab.


I started with scrapBook but after some time I realized that it is rather slowing one down. Mainly because you gotta use fully qualified names of classes like java.util.Map, cause only java.lang.* are implicitly imported. There is content assist, but nothing like "file cannot be resolved - import it"

As a result it is better having a class with Main method and do it there. Because you get all the eclipse Java Editor support you need. Alternatively use TestNG or JUnit to run one of your test methods. I like it better for this purpose than a Main class. I've never used runtime execution in debug mode for this purpose. I use it just for printing out values of variables.

The second option is eclipse-shell plugin. But it is the same issue. It is missing the IDE Java Editor support that is so useful. I believe it is the reason why these two options are not used much. One tries it out but realizes that it doesn't make sense without the Java Editor support.


You can always write a Main method in any class and run it.

But if you need that, you should get familiar with

Eclipse Plugin Development

Interpreter

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜