Evaluate code snippet [message #244357] |
Fri, 08 June 2007 07:55  |
Eclipse User |
|
|
|
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 #244557 is a reply to message #244379] |
Fri, 15 June 2007 07:37  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.06639 seconds