Bug 191488 - Interactive Java expression evaluator attached to project
Interactive Java expression evaluator attached to project
Status: NEW
Product: java
Classification: Unclassified
Component: Project
6.x
All All
: P3 with 15 votes (vote)
: TBD
Assigned To: Tomas Zezula
issues@java
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-10-30 18:17 UTC by DeepFrz
Modified: 2015-04-27 18:34 UTC (History)
7 users (show)

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description DeepFrz 2010-10-30 18:17:22 UTC
I have searched the web and have found several people asking about a Scrapbook feature (as in Eclipse Scrapbook) but could not find that a feature request has been filed. 

The scrapbook is a page that can be attached to a project in the IDE and can be used to evaluate or test run java code. A very handy feature indeed.
Comment 1 Jesse Glick 2010-11-01 14:27:00 UTC
The Evaluate window that appears when debugging the project is similar, though the UI is clumsy for writing complex expressions, and they are not persisted. This is also not available without starting the app, whereas e.g. with jrunscript you can interactively check various functions so long as they require no special services to be running.

This feature could surely be implemented as an add-on plugin. I am not sure what the best way to parse and evaluate Java code interactively is; you probably need to use JSR 199 to actually compile a block somehow, as if it formed a method body.
Comment 2 Martin Entlicher 2010-11-02 21:16:39 UTC
I haven't tried Eclipse' Scrapbook, but I do not think this has anything to do with debugger.

IMHO it can be implemented either by compiling the user-written code in a dedicated class and running that, or by interpreting the code (in a similar way that is done by debugger, but instead of delegating the execution through debugger, run it in a special class loader).

IMHO this is about execution, not debugging.
Perhaps it would be nice if one can also debug the code snippet, but the main concept needs to be implemented in Java project, I think.
Comment 3 DeepFrz 2010-11-03 01:43:14 UTC
http://eclipsetutorial.sourceforge.net/totalbeginner.html

The above link is to a download page for a beginner's tutorial on java and Eclipse. The tutorial on the Scrapbook is in lesson #3, unfortunately all lessons must be downloaded in order to watch it. I think the Scrapbook feature would make a very nice enhancement to Netbeans. Very handy for evaluating code snippets without having to build an entire class or even a method. Perhaps more valuable to a beginner (again) like me than to an experienced developer.

I would encourage anyone who is interested in this feature to download and watch lesson #3 of the above tutorial.
Comment 4 snailgem 2010-11-17 22:24:13 UTC
here is the help page from eclipse for this feature:
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/ref-34.htm

and here is another useful link:
http://www.eclipsezone.com/eclipse/forums/t61137.html

what is not clear from these links, though, is that this is not only an expression evaluator. if you attach a scrapbook page to an eclipse project, you can run things related to the classes in that project from the scrapbook: instantiate an object, call its methods, call a main method etc.

it would be terrific to have something this useful in eclipse!
Comment 5 snailgem 2010-11-17 22:31:34 UTC
(erratum to comment #4)

> it would be terrific to have something this useful in *netbeans*!
Comment 6 MrRemedy 2012-05-26 03:02:48 UTC
Having this feature is the current time saver tool holding me back from totally switching to Net beans IDE.

More votes please.
Comment 7 Jesse Glick 2012-05-29 23:27:10 UTC
(In reply to comment #2)
> compiling the user-written code in a dedicated class and running that

That is fine and probably not too hard; requires nothing specifically from the project system, just a ClassPath[] context from GlobalPathRegistry (EXECUTE).

The hard part would be displaying the object inspector on results as the Eclipse scrapbook does. Of course this is not absolutely necessary - you could just display the toString() of each result - but a key feature. In NB this GUI currently exists only in the debugger and is not available for reuse.
Comment 8 Jesse Glick 2012-05-30 23:29:29 UTC
I committed contrib #ce13cee71654 with a very rudimentary scrapbook feature - no Java syntax highlighting or code completion, run blocks only (no expression evaluation or mixing imports with statements), no object inspector, no support for alternate boot classpaths, etc. But it does work to keep track of some sample code snippets and run them against the project's classpath (use println(...) to display results).
Comment 9 markiewb 2013-11-22 23:12:47 UTC
FYI: Geertjan took jglicks code and created a proof-of-concept plugin out of it

https://blogs.oracle.com/geertjan/entry/java_scrapbook_for_netbeans_ide

Perhaps this could be improved and integrated?
Comment 10 twolf2919 2014-07-17 18:27:46 UTC
Jesse's and Geertjan's plugin is a good start, but it doesn't seem to handle anything more than simple expressions.

For instance, I often find myself writing a little java program to interpret some file content (mostly because I'm much more familiar with Java syntax than with shell scripting).  The way I have to do it now is: (1) create a class "Project->New->New Java Class", (2) manually type in its main(), (3) type in my code, (4) Right-click->Run File.

The current plugin doesn't seem to appear import statements, so how would I write any snippet dealing with IO?  I can't see a way.

In my simple world, a "scrap book" would be a partially editable .java file (similar to "forms" java files the GUI builder creates) with an editable "imports" area and an editable "content" area that forms the body of "main()". Optionally, there's be a "Run" button at the bottom of the panel (but the current rightclick->Run File is sufficient).
Comment 11 twolf2919 2014-07-17 18:45:53 UTC
(In reply to twolf2919 from comment #10)
> Jesse's and Geertjan's plugin is a good start, but it doesn't seem to handle
> anything more than simple expressions.
> 
> For instance, I often find myself writing a little java program to interpret
> some file content (mostly because I'm much more familiar with Java syntax
> than with shell scripting).  The way I have to do it now is: (1) create a
> class "Project->New->New Java Class", (2) manually type in its main(), (3)
> type in my code, (4) Right-click->Run File.

To be clear, I understand that I could just always create a "Scratch" java file at the root of my project whenever I create a new Project and use it whenever I want to do something like the above.  I've done that in the past.  The problem is that the project source is under source control and I always have to be vigilant that I don't accidentally commit this "Scrap" java file with the rest of my changed project sources.  A few times I wasn't.

Also, I see that the original intent of this enhancement request was merely to support "expression evaluation" - which Geertjan's plugin does do - so maybe I should be filing my own enhancement issue - but since several others' comments expressed a desire for something more than just expression evaluation, I'll keep it here for now.
Comment 12 jessgwiii 2015-04-27 03:33:32 UTC
I currently use an ARM based embedded system for my programming needs,  I found that NetBeans works flawlessly.  Eclipse does not even offer a version of their IDE in ARM newer than 3.8.  After using Eclipse I found a lot of features that NetBeans offers and found the transition to be quite painless.  There are features I like better on NetBeans, but no ScrapBook, at least one that works.  I found a plugin that installs and seems to function, but no snippets run, not even the simplest System.out.println("Hello World");  Everything gives an error [/tmp/_.java:1: warning: '_' used as an identifier] .  A code snippet evaluator is handy for learning the java library and testing parts of your program, it is a shame that NetBeans does not have something similar.
Comment 13 markiewb 2015-04-27 18:34:02 UTC
(In reply to jessgwiii from comment #12)
> I currently use an ARM based embedded system for my programming needs,  I
> found that NetBeans works flawlessly.  Eclipse does not even offer a version
> of their IDE in ARM newer than 3.8.  After using Eclipse I found a lot of
> features that NetBeans offers and found the transition to be quite painless.
> There are features I like better on NetBeans, but no ScrapBook, at least one
> that works.  I found a plugin that installs and seems to function, but no
> snippets run, not even the simplest System.out.println("Hello World"); 
> Everything gives an error [/tmp/_.java:1: warning: '_' used as an
> identifier] .  A code snippet evaluator is handy for learning the java
> library and testing parts of your program, it is a shame that NetBeans does
> not have something similar.

@jessgwiii: Please do not change the version property of issues. This property states when the issue has been filed. Reset to original value 6.x

If the plugin, you use, does not work, please contact the author of the plugin and report the bug!


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo