Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [JET] About the status of JET or JET2.
[JET] About the status of JET or JET2. [message #61635] Mon, 25 May 2009 17:08 Go to next message
Mikai Yang is currently offline Mikai YangFriend
Messages: 149
Registered: July 2009
Senior Member
Hi,
I am implementing a tool involving a code generator. I have come across a number of tools for code generation, such as Xtext, TCS and JET. I have spent
much time on reviewing XText and TCS. I found XText just produces code in one line and TCS is not maitained at all. It seems both of them can not suit my use.
I really have no time to review JET. If you can summarize the latest status of JET, especially its usability, you will be highly appreciated.

Regards
Michael.
Re: [JET] About the status of JET or JET2. [message #61683 is a reply to message #61635] Mon, 25 May 2009 19:35 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Xtext is not itself used for code generation, rather M2T Xpand is the
technology used for code generation in Xtext. And it does not produce
"code in one line", when you mean that it outputs just one line of code.
M2T Xpand is a highly comfortable templating technology.

Best,
~Karsten

On 25.05.09 19:08, Michael wrote:
> Hi,
> I am implementing a tool involving a code generator. I have come across
> a number of tools for code generation, such as Xtext, TCS and JET. I
> have spent
> much time on reviewing XText and TCS. I found XText just produces code
> in one line and TCS is not maitained at all. It seems both of them can
> not suit my use.
> I really have no time to review JET. If you can summarize the latest
> status of JET, especially its usability, you will be highly appreciated.
>
> Regards
> Michael.


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: [JET] About the status of JET or JET2. [message #61727 is a reply to message #61635] Tue, 26 May 2009 07:15 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Michael,

the formatting of Xtext will be improved / fixed till the relase in
June. At that point it will be possible to specify pretty printing
information for your models.

But if you're really just looking for a solution to do code generation
this is the right newsgroup since all our code generation languages live
here.
We have three wonderful template languages:
- Jet2 (JSP-like, highly configurable, Xpath expressions, etc.)
- Acceleo (Implementation of Model 2 Text Spec from OMG)
- Xpand (statically typed, template language, supporting OCL-like
expressions with Java-like syntax)

So you have the choice, I guess all three work nice :-)

Cheers,
Sven

Michael schrieb:
> Hi,
> I am implementing a tool involving a code generator. I have come
> across a number of tools for code generation, such as Xtext, TCS and
> JET. I have spent
> much time on reviewing XText and TCS. I found XText just produces code
> in one line and TCS is not maitained at all. It seems both of them can
> not suit my use.
> I really have no time to review JET. If you can summarize the latest
> status of JET, especially its usability, you will be highly appreciated.
>
> Regards
> Michael.
Re: [JET] About the status of JET or JET2. [message #61774 is a reply to message #61727] Tue, 26 May 2009 12:05 Go to previous messageGo to next message
Mikai Yang is currently offline Mikai YangFriend
Messages: 149
Registered: July 2009
Senior Member
Sven Efftinge wrote:
> Hi Michael,
>
> the formatting of Xtext will be improved / fixed till the relase in
> June. At that point it will be possible to specify pretty printing
> information for your models.
>
> But if you're really just looking for a solution to do code generation
> this is the right newsgroup since all our code generation languages live
> here.
> We have three wonderful template languages:
> - Jet2 (JSP-like, highly configurable, Xpath expressions, etc.)
> - Acceleo (Implementation of Model 2 Text Spec from OMG)
> - Xpand (statically typed, template language, supporting OCL-like
> expressions with Java-like syntax)
>
> So you have the choice, I guess all three work nice :-)
>
> Cheers,
> Sven
>
> Michael schrieb:
>> Hi,
>> I am implementing a tool involving a code generator. I have come
>> across a number of tools for code generation, such as Xtext, TCS and
>> JET. I have spent
>> much time on reviewing XText and TCS. I found XText just produces code
>> in one line and TCS is not maitained at all. It seems both of them
>> can not suit my use.
>> I really have no time to review JET. If you can summarize the latest
>> status of JET, especially its usability, you will be highly appreciated.
>>
>> Regards
>> Michael.
Hi Sven:
Thanks for your help. I surfed to the download page of M2T project to look for the build of Jet2, however I just found the
the one for Jet rather than Jet2. I am quite confused; What does Jet2 refer to: the second version of Jet? Has Jet2
already become stable now? What's the major difference between Jet and Jet2?
Thanks.
Regards.
Michael.
Re: [JET] About the status of JET or JET2. [message #61798 is a reply to message #61774] Tue, 26 May 2009 13:04 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Michael:

The JET version you get from the M2T download site is what is JET2. For
the record, JET1 would be the version of JET that is part of EMF (in the
org.eclipse.emf.codegen plug-in).

The main similarities and differences between JET1 and JET2

* both are based on JSP concepts. But, JET1 only allows use of scriptlets
(embedded Java statements) and expressions (embedded Java expressions),
while JET2 supports tag libraries as well.

* JET1 assumes you are going to write a Java program that will invoke your
templates and handle the template results. JET2 provides tag libraries
that allow you to write entire transformations without Java code and
without needing to be familiar with the Eclipse APIs.

* At the template interface level, JET1 and JET2 templates implement
different interfaces. For JET1, each compiled template implements a method:

String generate(Object argument)

For JET2, each compiled template implements a method:

void generate(JET2Context context, JET2Writer out)

(This only matters if you want to invoke templates from Java code. As I
said above, it is generally possible to avoid the writing of any Java code
when using JET2.

* JET2 allows you to navigate your model using XPath expressions. Although
XPath is typically used for XML documents, JET2 can handle other input
models, including anything based on EMF/ECore.

Hope this helps.
Re: [JET] About the status of JET or JET2. [message #61890 is a reply to message #61798] Wed, 27 May 2009 19:45 Go to previous messageGo to next message
Mikai Yang is currently offline Mikai YangFriend
Messages: 149
Registered: July 2009
Senior Member
Hi Paul:
Your reply is extremely helpful. However I still have the following quesitons:


> * JET1 assumes you are going to write a Java program that will invoke
> your templates and handle the template results. JET2 provides tag
> libraries that allow you to write entire transformations without Java
> code and without needing to be familiar with the Eclipse APIs.

1) You meant that JET2 supports both Java scriplets and tag. Does this mean that tags and Java scripts can make apperance in the same JET2 template?
2) Do you have any example JET2 template including Java scriplets and tags simulataneously?

> * JET2 allows you to navigate your model using XPath expressions.
> Although XPath is typically used for XML documents, JET2 can handle
> other input models, including anything based on EMF/ECore.

3) What a pity! I failed to find examples about GET2 handling an EMF ecore model? Would you please provide one?
4) In fact, I would like to incorporate a code generator into a standalone ATL tranformation application. How can I do it with GET2-produced code generator? I prefer the code generator to
produce code directly from in-memory target models produced by atl transformations, rather than from serialized xmi files. So, is this possible
for JET2?
Thanks. So sorry for these silly questions.

Regards!
Michael.


Paul Elder wrote:
> Michael:
>
> The JET version you get from the M2T download site is what is JET2. For
> the record, JET1 would be the version of JET that is part of EMF (in the
> org.eclipse.emf.codegen plug-in).
>
> The main similarities and differences between JET1 and JET2
>
> * both are based on JSP concepts. But, JET1 only allows use of
> scriptlets (embedded Java statements) and expressions (embedded Java
> expressions), while JET2 supports tag libraries as well.
>
> * JET1 assumes you are going to write a Java program that will invoke
> your templates and handle the template results. JET2 provides tag
> libraries that allow you to write entire transformations without Java
> code and without needing to be familiar with the Eclipse APIs.
>
> * At the template interface level, JET1 and JET2 templates implement
> different interfaces. For JET1, each compiled template implements a method:
>
> String generate(Object argument)
>
> For JET2, each compiled template implements a method:
>
> void generate(JET2Context context, JET2Writer out)
>
> (This only matters if you want to invoke templates from Java code. As I
> said above, it is generally possible to avoid the writing of any Java
> code when using JET2.
>
> * JET2 allows you to navigate your model using XPath expressions.
> Although XPath is typically used for XML documents, JET2 can handle
> other input models, including anything based on EMF/ECore.
>
> Hope this helps.
>
Re: [JET] About the status of JET or JET2. [message #61914 is a reply to message #61890] Thu, 28 May 2009 07:28 Go to previous messageGo to next message
fabio boldrini is currently offline fabio boldriniFriend
Messages: 4
Registered: July 2009
Junior Member
I little example in my JET transformation that take all the xml file in
the directory where the generation was started and set it in $content
The scriplet are JSP like. For example some tag are inside a for.

For understand how to work with the JET api on the scriplet see the
generated .java from the transformation.


<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>

<%-- add the project.xml content on the project var --%>
<c:load url="{$org.eclipse.jet.resource.parent.fullPath}/project.xml "
var="project" urlContext='workspace'/>

<%-- Loading in $content all the xml in the directory where the
transformation was started --%>
<c:loadContent var="content">
<content>
</content>
</c:loadContent><%
//-- Now i take all the file name of the xml file
String path =
(String)context.getVariable("org.eclipse.jet.resource.parent.location ");

java.io.File dir = new java.io.File(path);

java.io.File[] directoryChild = dir.listFiles(new java.io.FileFilter() {

public boolean accept(java.io.File dir) {
return dir.isDirectory() && (!".svn".equals(dir.getName()));
}

});

java.io.File[] directoryXml = new
java.io.File[directoryChild.length+1];
directoryXml[0] = dir;
for (int i=0; i < directoryChild.length; i++) {
directoryXml[i+1] = directoryChild[i];
}

for (int j=0; j < directoryXml.length; j++) {
dir = directoryXml[j];
java.io.File[] children = dir.listFiles(new java.io.FileFilter() {

public boolean accept(java.io.File file) {
if (file == null) return false;
String name = file.getName();
return
name.endsWith(".xml") &&
!"project.xml".equals(name) &&
!file.isDirectory()
;
}
});

//--Here a for where i set the variable xml_file_path
for (int i = 0; i < children.length ; i++) {
context.setVariable("xml_file_path",
context.getVariable("org.eclipse.jet.resource.parent.fullPath ")
+ ((j==0) ? "" : "/" + dir.getName() )
+ "//"
+ children[i].getName()
);
%><c:log>@<c:get select="$xml_file_path"/></c:log><%--
load the xml in $view
--%><c:load url="{$xml_file_path}" var="view" urlContext='workspace'
type='xml'/><%--
copy the &view/view in &content/content
--%><c:copyElement select="$view/view" toSelect="$content/content"
name="view"/><%--
--%>
<%
}
}
%>
<%-- ---------- --%>


Michael wrote:

> 1) You meant that JET2 supports both Java scriplets and tag. Does this mean
that tags and Java scripts can make apperance in the same JET2 template?
> 2) Do you have any example JET2 template including Java scriplets and tags
simulataneously?

> Thanks. So sorry for these silly questions.

> Regards!
> Michael.
Re: [JET] About the status of JET or JET2. [message #61936 is a reply to message #61914] Thu, 28 May 2009 12:21 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Fabio:

Thanks for the example! Michael I hope that helps.

On a point if style, I prefer to write as little Java as possible in my
templates. Some reasons:

* Java code (and JET tags, for that matter) get in the way of seeing the
static part of the template - if you can't 'see' the structure of the
text you are generating, it is hard to justify using a template in the
first place.
* I have probably been too heavily influenced by JSP, where some
cultures feel it is bad practice to use Java code.
* I particularly don't like scriptlets that open a statement block that
is closed later...

<% for(...) { %>
... lots of template text ...
<% } %>

That looks nice a neat here, but when you have lots of text, and lots of
these blocks, it becomes hard to read (and get right). For an example of
this, take a look at the JET template that generates Java code from a
JET template:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.m2t/org .eclipse.jet/plugins/org.eclipse.jet/templates/v2/jet2java.j et?revision=1.9&root=Modeling_Project&view=markup

I wrote this, but I can barely read it. And I typically inject a Java
compile error every time I modify it. It's on my 'someday, I should
change this list'.

Here is some advice on making Java code in templates work better...

1) put large blocks of Java code into a utility class. Having:

<% MyUtil.somethingComplicated(...); %>

in a template is much more appealing than having the code inline. As an
added bonus, you get to use the Java editor to edit your Java code.

2) Consider whether you code could be moved to a custom JET tag or
custom XPath function.

3) Keep things short. Try not to do calculation in the template that is
producing content. (This applies JET tags as well as to Java code.)

Finally, the upcoming release of JET includes some improvements on the
'keep things short' front. Take a look at these 'What's New' items:

http://wiki.eclipse.org/M2T-JET/Whats_New_in_1.0_%28Galileo% 29#Compact_alternative_to_c:get_tag

http://wiki.eclipse.org/M2T-JET/Whats_New_in_1.0_%28Galileo% 29#JET_tags_can_now_change_the_XPath_context_object.2C_allow ing_for_shorter_expressions

Paul
Re: [JET] About the status of JET or JET2. [message #61956 is a reply to message #61890] Thu, 28 May 2009 12:42 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Michael wrote:
> 1) You meant that JET2 supports both Java scriplets and tag. Does this
> mean that tags and Java scripts can make apperance in the same JET2
> template?

Yes. Fabio gave an example in another reply.

> 2) Do you have any example JET2 template including Java scriplets and
> tags simulataneously?

Yes. Again, Fabio's response showed that.

>
> 3) What a pity! I failed to find examples about GET2 handling an EMF
> ecore model? Would you please provide one?

I don't think I have a public example right now. But here is a link to a
newsgroup post on how JETs XPath engine works with EObjects (and UML2
elements, which are EObjects)

http://dev.eclipse.org/newslists/news.eclipse.modeling.m2t/m sg01117.html

The bottom line is, it works quite nicely.

> 4) In fact, I would like to incorporate a code generator into a
> standalone ATL tranformation application. How can I do it with
> GET2-produced code generator? I prefer the code generator to
> produce code directly from in-memory target models produced by atl
> transformations, rather than from serialized xmi files. So, is this
> possible
> for JET2?

From a 'Run Configuration', JET expects to 'load' a model from disk.
How that is done is determined by a 'modelLoader'. In the case of an XMI
file generated by an EMF model, specify the 'org.eclipse.jet.emf' model
loader in your JET transforms plugin.xml. With that JET will do its best
to find the right EMF resource factory, and load the model as EObjects!

If you have an model in memory already, JET has an API:

JET2Plaform.runTransformOnObject("jet-plugin-id", rootOfYourModel,
[predefinedJETVariablesMap,] progressMonitor);

For behavior equivalent to what you see from the Run dialog, pass an EMF
Resouce object as 'rootOfYourModel'.

You mention 'stand-alone application'. JET2 requires Eclipse, but you
can run it headlessly (that is, without a UI). Ask if you want more details.


> Thanks. So sorry for these silly questions.
>

There are no silly questions :-)

Paul
Re: [JET] About the status of JET or JET2. [message #62029 is a reply to message #61956] Thu, 28 May 2009 17:34 Go to previous messageGo to next message
Mikai Yang is currently offline Mikai YangFriend
Messages: 149
Registered: July 2009
Senior Member
Hi Paul:
Your reply in in great detail. Now I am so clear about my previuos questions. As for incorporating Jet2-produced generator in a standalone Java application, I think it is better for somebody to
list library required at least.
Thanks.
Michael




Paul Elder wrote:
> Michael wrote:
>> 1) You meant that JET2 supports both Java scriplets and tag. Does this
>> mean that tags and Java scripts can make apperance in the same JET2
>> template?
>
> Yes. Fabio gave an example in another reply.
>
>> 2) Do you have any example JET2 template including Java scriplets and
>> tags simulataneously?
>
> Yes. Again, Fabio's response showed that.
>
>>
>> 3) What a pity! I failed to find examples about GET2 handling an EMF
>> ecore model? Would you please provide one?
>
> I don't think I have a public example right now. But here is a link to a
> newsgroup post on how JETs XPath engine works with EObjects (and UML2
> elements, which are EObjects)
>
> http://dev.eclipse.org/newslists/news.eclipse.modeling.m2t/m sg01117.html
>
> The bottom line is, it works quite nicely.
>
>> 4) In fact, I would like to incorporate a code generator into a
>> standalone ATL tranformation application. How can I do it with
>> GET2-produced code generator? I prefer the code generator to
>> produce code directly from in-memory target models produced by
>> atl transformations, rather than from serialized xmi files. So, is
>> this possible
>> for JET2?
>
> From a 'Run Configuration', JET expects to 'load' a model from disk.
> How that is done is determined by a 'modelLoader'. In the case of an XMI
> file generated by an EMF model, specify the 'org.eclipse.jet.emf' model
> loader in your JET transforms plugin.xml. With that JET will do its best
> to find the right EMF resource factory, and load the model as EObjects!
>
> If you have an model in memory already, JET has an API:
>
> JET2Plaform.runTransformOnObject("jet-plugin-id", rootOfYourModel,
> [predefinedJETVariablesMap,] progressMonitor);
>
> For behavior equivalent to what you see from the Run dialog, pass an EMF
> Resouce object as 'rootOfYourModel'.
>
> You mention 'stand-alone application'. JET2 requires Eclipse, but you
> can run it headlessly (that is, without a UI). Ask if you want more
> details.
>
>
>> Thanks. So sorry for these silly questions.
>>
>
> There are no silly questions :-)
>
> Paul
Re: [JET] About the status of JET or JET2. [message #62123 is a reply to message #61936] Fri, 29 May 2009 12:07 Go to previous message
fabio boldrini is currently offline fabio boldriniFriend
Messages: 4
Registered: July 2009
Junior Member
I agree.

I overused java in this case, and on debug it was painful.

Customtag scared me(i'm not a plugin/extension point master) but the
static method in a java class would have been i nice idea!

ps.the 1.0 features are very nice!

Paul Elder wrote:

> Fabio:

> Thanks for the example! Michael I hope that helps.

> On a point if style, I prefer to write as little Java as possible in my
> templates. Some reasons:

> * Java code (and JET tags, for that matter) get in the way of seeing the
> static part of the template - if you can't 'see' the structure of the
> text you are generating, it is hard to justify using a template in the
> first place.
> * I have probably been too heavily influenced by JSP, where some
> cultures feel it is bad practice to use Java code.
> * I particularly don't like scriptlets that open a statement block that
> is closed later...

> <% for(...) { %>
> ... lots of template text ...
> <% } %>

> That looks nice a neat here, but when you have lots of text, and lots of
> these blocks, it becomes hard to read (and get right). For an example of
> this, take a look at the JET template that generates Java code from a
> JET template:

>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.m2t/org .eclipse.jet/plugins/org.eclipse.jet/templates/v2/jet2java.j et?revision=1.9&root=Modeling_Project&view=markup

> I wrote this, but I can barely read it. And I typically inject a Java
> compile error every time I modify it. It's on my 'someday, I should
> change this list'.

> Here is some advice on making Java code in templates work better...

> 1) put large blocks of Java code into a utility class. Having:

> <% MyUtil.somethingComplicated(...); %>

> in a template is much more appealing than having the code inline. As an
> added bonus, you get to use the Java editor to edit your Java code.

> 2) Consider whether you code could be moved to a custom JET tag or
> custom XPath function.

> 3) Keep things short. Try not to do calculation in the template that is
> producing content. (This applies JET tags as well as to Java code.)

> Finally, the upcoming release of JET includes some improvements on the
> 'keep things short' front. Take a look at these 'What's New' items:

>
http://wiki.eclipse.org/M2T-JET/Whats_New_in_1.0_%28Galileo% 29#Compact_alternative_to_c:get_tag

>
http://wiki.eclipse.org/M2T-JET/Whats_New_in_1.0_%28Galileo% 29#JET_tags_can_now_change_the_XPath_context_object.2C_allow ing_for_shorter_expressions

> Paul
Previous Topic:[Announce] M2T XPAND 0.7.0RC2 is available
Next Topic:[JET] Collecting Metrics
Goto Forum:
  


Current Time: Thu Apr 18 00:20:44 GMT 2024

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

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

Back to the top