Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [JET] Inconsistent results for getClassifierID()
[JET] Inconsistent results for getClassifierID() [message #523547] Fri, 26 March 2010 14:22 Go to next message
Eclipse UserFriend
I found some inconsistent behavior of the method getClassifierID() of EClassifier when using JET:

  • In the generated Java code IDs are assigned first to classes then to datatypes.
  • JET assigns IDs to all classifiers in the order of appearance in a package.


An example: I have the following model (in emfatic syntax):
@namespace(uri="http:/example.org/xxx", prefix="xxx")
package xxx;

datatype ddd : java.lang.String;

class ccc {
   attr ddd d;
}


From this I generate an Ecore model. And with a standard .genmodel file I generate Java code.

Here is some test code using the generated Java code:
import org.eclipse.emf.ecore.EClassifier;

public class Test {
    public static void main(String[] args) {
        for (EClassifier c : xxx.XxxPackage.eINSTANCE.getEClassifiers())
            System.out.format("%d: %s\n", c.getClassifierID(), c.getName());
    }
}

It has this result:
0: ccc
1: ddd

I also use JET to generate some code from the model. (Actually it is C++ code, so I cannot use getClassiferID() at runtime but must use it in the template.) A largely simplified JET template:
<%@jet imports="org.eclipse.emf.ecore.*"%>
<c:iterate var="thePackage" select="/EPackage">
<%
EPackage pkg = (EPackage)context.getVariable("thePackage");
for (EClassifier c : pkg.getEClassifiers()) {
%>
<%= c.getClassifierID() %>: <%= c.getName() %>
<%
}
%>
</c:iterate>

And here is the generated file:
0: ddd
1: ccc

That is, the assignment of IDs to classifiers is not the same as above.

Is this a known problem? I cannot imagine that I am the first one to run into this.
This looks like a bug to me, but I don't know on which side.

My current workaround is to put the datatypes after the classes in the model.
Do you have any better suggestions?

Best Regards,
Heribert.

PS: I'm using the "Eclipse Modeling Tools" distribution, recently updated to 3.5.2.

[Updated on: Fri, 26 March 2010 14:27] by Moderator

Re: [JET] Inconsistent results for getClassifierID() [message #523569 is a reply to message #523547] Fri, 26 March 2010 17:22 Go to previous message
Eclipse UserFriend
Heribert,

Classifier IDs always correspond to the position of the classifier in
the EPackage's getEClassifiers but the generator partitions the
classifiers by type to produce a different order than they appear in the
original package. You need to consult with the GenPackage's
getClassifierValue to be sure you get the generated one if that's what
you need.


Heribert Schütz wrote:
> I found some inconsistent behavior of the method getClassifierID() of
> EClassifier when using JET:
>
> In the generated Java code IDs are assigned first to classes then to
> datatypes.
> JET assigns IDs to all classifiers in the order of appearance in a
> package.
>
>
> An example: I have the following model (in emfatic syntax):
>
> @namespace(uri="http:/example.org/xxx", prefix="xxx")
> package xxx;
>
> datatype ddd : java.lang.String;
>
> class ccc {
> attr ddd d;
> }
>
>
> From this I generate an Ecore model. And with a standard .genmodel
> file I generate Java code.
>
> Here is some test code using the generated Java code:
>
> import org.eclipse.emf.ecore.EClassifier;
>
> public class Test {
> public static void main(String[] args) {
> for (EClassifier c : xxx.XxxPackage.eINSTANCE.getEClassifiers())
> System.out.format("%d: %s\n", c.getClassifierID(),
> c.getName());
> }
> }
>
> It has this result:
>
> 0: ccc
> 1: ddd
>
> I also use JET to generate some code from the model. (Actually it is
> C++ code, so I cannot use getClassiferID() at runtime but must use it
> in the template.) A largely simplified JET template:
>
> <%@jet imports="org.eclipse.emf.ecore.*"%>
> <c:iterate var="thePackage" select="/EPackage">
> <%
> EPackage pkg = (EPackage)context.getVariable("thePackage");
> for (EClassifier c : pkg.getEClassifiers()) {
> %>
> <%= c.getClassifierID() %>: <%= c.getName() %>
> <%
> }
> %>
> </c:iterate>
>
> And here is the generated file:
>
> 0: ddd
> 1: ccc
>
> That is, the assignment of IDs to classifiers is not the same as above.
>
> Is this a known problem? I cannot imagine that I am the first one to
> run into this.
> This looks like a bug to me, but I don't know on which side.
>
> My current workaround is to put the datatypes after the classes in the
> model.
> Do you have any better suggestions?
>
> Best Regards,
> Heribert.
Previous Topic:[Acceleo] Headless exeuction after installation
Next Topic:Proposal provider for a rule
Goto Forum:
  


Current Time: Tue Jul 08 01:41:42 EDT 2025

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

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

Back to the top