Home » Modeling » EMF » [JET]JETEmitter Problem when running workspace
|
Re: [JET]JETEmitter Problem when running workspace [message #910609 is a reply to message #910485] |
Mon, 10 September 2012 04:52 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Comments below.<br>
<br>
<div class="moz-cite-prefix">On 09/09/2012 10:29 PM, Yumin Zhou
wrote:<br>
</div>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">Hello
experts,
<br>
<br>
I want to generate code from one xml based on EMF with JETEmitter
in a new file wizard. I was able to generate helloWorld.txtjet
after running the new wizard. But when I tried to generate the xml
file information, I got blank file. One more thing, when I used
the java generated code directly, it worked. <br>
</blockquote>
So why are you doing it this way?<br>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">Here
is my generate java code:
<br>
<br>
private void generate(DocumentRoot documentRoot, IProgressMonitor
monitor) throws JETException{
<br>
String pluginId = "jet.project"; <br>
</blockquote>
Is this bundle installed in your running Eclipse? I.e., it's not a
project in the workspace is it?<br>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">
String base =
Platform.getBundle(pluginId).getEntry("/").toString();
String relativeUri = "templates/generate.txtjet"; <br>
</blockquote>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">
JETEmitter emitter = new JETEmitter(base + relativeUri,</blockquote>
I suppose this is equivalent too
Platform.getBundle(pluginId).getEntry("templates/generate.txtjet").toString().<br>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">getClass().getClassLoader());</blockquote>
Are you expecting this approach to be able to compile the template
dynamically or you're expecting it only to ever use the already
compiled template? Note that EMF's generator uses<br>
<blockquote> protected JETEmitter
createJETEmitter(JETEmitterDescriptor jetEmitterDescriptor)<br>
{<br>
JETEmitter jetEmitter = new JETEmitter(getTemplatePath(),
jetEmitterDescriptor.templatePathName,
getClass().getClassLoader());<br>
</blockquote>
And we set up the template path to point at the templates folder in
the loaded bundle. You might want to set a breakpoint in
org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.createJETEmitter(JETEmitterDescriptor)
and see how the arguments are set up for EMF's use JETEmitter for
generating model code from Ecore/GenModel.<br>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">
<br>
IProgressMonitor sub = new SubProgressMonitor(monitor, 1);
String result = emitter.generate(sub, new Object[]
{documentRoot});
<br>
monitor.worked(1); }
<br>
<br>
Has somebody any idea about it? It seems that it cannot load the
documentRoot object after pressing the finish button. <br>
<br>
<br>
<br>
</blockquote>
<br>
</body>
</html>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | |
Re: [JET]JETEmitter Problem when running workspace [message #911137 is a reply to message #911075] |
Tue, 11 September 2012 03:46 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Yumin,
Comments below.
On 11/09/2012 1:36 AM, Yumin Zhou wrote:
> Ed,
>
> Thank you for replying so soon.
>
> I thought the details might help me to explain the first question
> clearly.
> <br>String pluginId = "jet.project"; <br>
> </blockquote>
> Is this bundle installed in your running Eclipse? I.e., it's not a
> project in the workspace is it?<br>
>
> It is installed in running eclipse because I created the "Hello World"
> code after running. The "Hello World" template is in this project
> "jet.project", too.
>
> <blockquote cite="mid:k2iu87$mrj$mailto:1@xxxxxxxx"
> type="cite"> String base =
> Platform.getBundle(pluginId).getEntry("/").toString(); String
> relativeUri = "templates/generate.txtjet"; <br>
> </blockquote>
> <blockquote cite="mid:k2iu87$mrj$mailto:1@xxxxxxxx"
> type="cite"> JETEmitter emitter = new JETEmitter(base +
> relativeUri,</blockquote>
> I suppose this is equivalent too
> Platform.getBundle(pluginId).getEntry("templates/generate.txtjet").toString().<br>
>
Be sure to actually try that call so you know it's actually finding that
entry in your bundle.
>
> I suppose, too. I think it is not the path problem, otherwise I
> wouldn't get the generated code "hello world", am I right?
I suppose so.
> What my problem seems that the generation doesn't get the object after
> running wizard.
Have you set a breakpoint to see what value of DocumentRoot is being
passed to the JETEmitter? In any case, if the templates are already
compiled and the resulting Java code for that are also compiled and
available in the installed IDE, and you aren't planning to support
dynamic templates (i.e., someone providing a modified version of the
template itself in the workspace), then you can use that compiled
template directly without the JETEmitter.
In the end, it's very hard to answer your question without all the
dynamic details, but if you set a breakpoint and trace through what
happens when you call generate on the emitter, you should be able to
track down what's going wrong.
>
> YM
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | | | | | | | | |
Goto Forum:
Current Time: Mon Sep 23 23:42:20 GMT 2024
Powered by FUDForum. Page generated in 0.07284 seconds
|