Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Evaluate code snippet
Evaluate code snippet [message #244357] Fri, 08 June 2007 07:55 Go to next message
Eclipse UserFriend
Originally posted by: diego.manilla.xeridia.com

Hi. I have a text box where the user must introduce code that evaluates to
something of a given type, and I need to validate that. For example, if
the target type is Integer, the user can input 'new Integer(5)', or
'Integer.valueOf("7")', but not 'new Long(7)';

I've seen the example on the IEvaluationContext Javadoc. The code itself
is this:

IJavaProject project = getJavaProject();
IEvaluationContext context = project.newEvaluationContext();
String codeSnippet = "int i= 0; i++";
ICodeSnippetRequestor requestor = ...;
context.evaluateCodeSnippet(codeSnippet, requestor, progressMonitor);

The problem is that seems that the interesting part is the "...". The
implementation of ICodeSnippetRequestor seems pretty complicated. Is there
any implementation that I can use? I found LocalEvaluationEngine, but I
have a problem with it: it asks for a IJavaDebugTarget instance on its
constructor, and a IJavaThread on its evaluate method. I managed to get an
instance of the first using an ILaunch reference (I don't know if it's the
way to do it), but I don't know where I can get a IJavaThread.

The JDT programmer's guide doesn't say anything about evaluating code
snippets, is there anything else I can read?

Thanks in advance
Re: Evaluate code snippet [message #244379 is a reply to message #244357] Fri, 08 June 2007 09:44 Go to previous messageGo to next message
Eclipse UserFriend
The Java Scrapbook editor uses this API to perform evaluations
(LocalEvaluationEngine - which you found). Yes, a lot goes on here -
basically it's up to the implementor of ICodeSnippetRequestor to deploy and
execute the resulting class files.

The scrapbook launches a VM in debug mode (IJavaDebugTarget) which can load
the generated class files and invoke the evaluation using JDI.

Darin Wright


"Diego Manilla "Su
Re: Evaluate code snippet [message #244557 is a reply to message #244379] Fri, 15 June 2007 07:37 Go to previous message
Eclipse UserFriend
Originally posted by: diego.manilla.xeridia.com

Thanks, Darin. I took a look at the source of JavaSnippetEditor and
ScrapBookLauncher classes and now I have something that is working.

Regards,
Diego.

Darin Wright wrote:

> The Java Scrapbook editor uses this API to perform evaluations
> (LocalEvaluationEngine - which you found). Yes, a lot goes on here -
> basically it's up to the implementor of ICodeSnippetRequestor to deploy and
> execute the resulting class files.

> The scrapbook launches a VM in debug mode (IJavaDebugTarget) which can load
> the generated class files and invoke the evaluation using JDI.

> Darin Wright
Previous Topic:Add feature based on Java project config
Next Topic:How to set up a JAVA_HOME based JRE ?
Goto Forum:
  


Current Time: Mon Jul 14 07:15:32 EDT 2025

Powered by FUDForum. Page generated in 0.06639 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top