[JET] Inconsistent results for getClassifierID() [message #523547] |
Fri, 26 March 2010 18:22 |
Heribert Schütz Messages: 24 Registered: July 2009 |
Junior Member |
|
|
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:
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:
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 18:27] Report message to a moderator
|
|
|
Re: [JET] Inconsistent results for getClassifierID() [message #523569 is a reply to message #523547] |
Fri, 26 March 2010 21:22 |
Ed Merks Messages: 33133 Registered: July 2009 |
Senior Member |
|
|
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.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.01876 seconds