Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325429 - Enums are not generated in the right source location when using annotationsmodel
Summary: Enums are not generated in the right source location when using annotationsmodel
Status: RESOLVED FIXED
Alias: None
Product: EMFT
Classification: Modeling
Component: Texo (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Martin Taal CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-16 06:00 EDT by Mark Hoffmann CLA
Modified: 2010-09-16 14:29 EDT (History)
1 user (show)

See Also:


Attachments
Sample ecore (1.67 KB, application/xml)
2010-09-16 06:00 EDT, Mark Hoffmann CLA
no flags Details
Sample Annotionsmodel (10.35 KB, application/octet-stream)
2010-09-16 06:00 EDT, Mark Hoffmann CLA
no flags Details
annotationsmodel with only an epackage annotation (3.15 KB, application/octet-stream)
2010-09-16 11:39 EDT, Martin Taal CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Hoffmann CLA 2010-09-16 06:00:20 EDT
Build Identifier: 20100617-1415

Texo 0.1.0-201008031709

Enums are not generated in the right source location when using annotationsmodel.
The java files contain the right package definition from the annotionsmodel, but they are generated in the default src location and not at the location of the annotionsmodel.

Further there are some wrong full qualified classes generated into the model factory.

See attached ecore and annotionsmodel.

Reproducible: Always
Comment 1 Mark Hoffmann CLA 2010-09-16 06:00:40 EDT
Created attachment 179014 [details]
Sample ecore
Comment 2 Mark Hoffmann CLA 2010-09-16 06:00:59 EDT
Created attachment 179015 [details]
Sample Annotionsmodel
Comment 3 Martin Taal CLA 2010-09-16 10:03:27 EDT
Hi Mark,
I reacted in the newsgroup for completeness:

Hi Mark,
I checked the annotations model and there are some strange in there. For example the Address eclass annotation has this eattribute:
qualifiedClassName="texo.test.Address"
however, the Person eclass has an ereference annotation for address with this eattribute:
type="test.Address"

This is the reason that there are compile errors in the generated code for the Person, as it refers to a type which does not get generated. It is best to have a quite empty annotationsmodel (so only annotate what you want to change, the rest is automatically generated). So to solve this I would remove all the ereference annotations.

To be sure, did you manually change the annotations model?

The reason that the ContactType enum is generated in a separate package is because its annotation has this eattribute set:
 qualifiedClassName="test.ContactType"

so therefore it ends up in the test package and not in the texo.test package.

gr. Martin
Comment 4 Mark Hoffmann CLA 2010-09-16 11:13:52 EDT
(In reply to comment #3)
> Hi Mark,
> I reacted in the newsgroup for completeness:
> 
> Hi Mark,
> I checked the annotations model and there are some strange in there. For
> example the Address eclass annotation has this eattribute:
> qualifiedClassName="texo.test.Address"
> however, the Person eclass has an ereference annotation for address with this
> eattribute:
> type="test.Address"
> This is the reason that there are compile errors in the generated code for the
> Person, as it refers to a type which does not get generated. It is best to have
> a quite empty annotationsmodel (so only annotate what you want to change, the
> rest is automatically generated). 

I just want to create the texo generated stuff in a certain package. My intention was to get something like the Base Package attribute in the genmodel.

> To be sure, did you manually change the annotations model?

I used the default editor and properties view that open for the annotationsmodel.
 
> The reason that the ContactType enum is generated in a separate package is
> because its annotation has this eattribute set:
>  qualifiedClassName="test.ContactType"

I have seen this. But the editor/properties view only allowes the attributes instanceClassName. I changed this to texo.test.ContactType. There is no proerty  in the code but the properties view doesn't show this attribute.

Regards,
Mark
Comment 5 Mark Hoffmann CLA 2010-09-16 11:27:21 EDT
Hi Martin,

what about extending the texo-annotations-model.ecore like this:

  <eClassifiers xsi:type="ecore:EClass" name="AnnotatedModel">
    <eStructuralFeatures xsi:type="ecore:EReference" name="annotatedEPackages" upperBound="-1"
        eType="#//AnnotatedEPackage" containment="true" eOpposite="#//AnnotatedEPackage/annotatedModel"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="basePackage" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
  </eClassifiers>

If your epackage is called 'test' and the basePackage is 'org.eclipse.texo', then all generate code should have the base: 'org.eclipse.texo.test'.

Regards, 
Mark
Comment 6 Martin Taal CLA 2010-09-16 11:38:36 EDT
Hi Mark,
Yes the packagepath eattribute in a way does this (although it is the complete packagename, so the epackagename won't be appended). 

I checked and with me the annotationsmodel editor allows you to set the qualifiedclassname for an eclass.

So the intended usage is:
* set the packagepath in an epackage annotation
* override any specific classname in the qualifiedclassname eattribute of the eclass annotation, these classes are then generated in another package than the packagepath set on epackage level.

gr. Martin
Comment 7 Martin Taal CLA 2010-09-16 11:39:50 EDT
Created attachment 179039 [details]
annotationsmodel with only an epackage annotation
Comment 8 Mark Hoffmann CLA 2010-09-16 12:01:50 EDT
(In reply to comment #6)
> Hi Mark,
> Yes the packagepath eattribute in a way does this (although it is the complete
> packagename, so the epackagename won't be appended). 
> 
> I checked and with me the annotationsmodel editor allows you to set the
> qualifiedclassname for an eclass.
You are right, but not for an Enum! It only shows the Instance Class Name.


> So the intended usage is:
> * set the packagepath in an epackage annotation
> * override any specific classname in the qualifiedclassname eattribute of the
> eclass annotation, these classes are then generated in another package than the
> packagepath set on epackage level.

I got it, now it worked for the classes, package and factory. The enum is still in the wrong package. Additionally I deleted the reference annotations.

Mark
Comment 9 Martin Taal CLA 2010-09-16 12:03:41 EDT
Hi Mark,
Ha good point, I will change this for the enum.

Strange that the enum is still in the wrong package. Did you also remove the enum annotation?

gr. Martin
Comment 10 Mark Hoffmann CLA 2010-09-16 12:17:37 EDT
(In reply to comment #9)
> Hi Mark,
> Ha good point, I will change this for the enum.
> 
> Strange that the enum is still in the wrong package. Did you also remove the
> enum annotation?
> 
> gr. Martin
I got it work. I changed the AnnotatedEENum attributes by hand:
instanceClassName, objectClassName and qualifiedClassName 
to the new path and it worked. 

The qualifiedClassName seems to generate the enum in the right src folder.
The objectClassName seems to be important for the ModelFactory generation.
The instanceClassName is important to generate the right references (in my Contact class and the factory)

<annotatedEClassifiers xsi:type="annotationsmodel:AnnotatedEEnum">
      <eEnum href="test.ecore#//ContactType"/>
      <eEnumAnnotations xsi:type="modelannotations:EEnumModelGenAnnotation" name="ContactType" qualifiedClassName="texo.test.ContactType" simpleClassName="ContactType" generateCode="true" ownerEPackageAnnotation="//@annotatedEPackages.0/@ePackageAnnotations.0" instanceClassName="texo.test.ContactType" objectClassName="texo.test.ContactType" enum="true" dateType="false" automaticStringConversion="false" itemType="java.lang.Object"/>
      <annotatedEEnumLiterals>
        <eEnumLiteral href="test.ecore#//ContactType/PHONE"/>
      </annotatedEEnumLiterals>
      <annotatedEEnumLiterals>
        <eEnumLiteral href="test.ecore#//ContactType/EMAIL"/>
      </annotatedEEnumLiterals>
    </annotatedEClassifiers>

Regards,
Mark
Comment 11 Martin Taal CLA 2010-09-16 12:22:48 EDT
But why don't you just remove the complete enum annotation? That should also work.

gr. Martin
Comment 12 Mark Hoffmann CLA 2010-09-16 13:06:19 EDT
(In reply to comment #11)
> But why don't you just remove the complete enum annotation? That should also
> work.
Because sometimes, the trees are so close, that you doesn't see them ;-)

(in German: Man sieht den Wald vor lauter Bäumen nicht)

I removed the enum annotation, all reference annotations, the attribute annotation the refers to the enum, changed the 'package path' in the epackage annotation to my needs and set the qualified class name in the eclass annotations.

Everything is fine. The generated code is without any error!

Only the classifier id's are still wrong ;-)

Thank you very much.
You can close the bug, I think.

Regards,
Mark
Comment 13 Martin Taal CLA 2010-09-16 13:09:13 EDT
Hmm, the classifier id is correctly generated with me... Did you put generatednot in the ModelPackage file maybe?

I am committing some changes to the enum generation, after that (and a successfull build) I will close the issue.

gr. Martin
Comment 14 Mark Hoffmann CLA 2010-09-16 13:54:05 EDT
(In reply to comment #13)
> Hmm, the classifier id is correctly generated with me... Did you put
> generatednot in the ModelPackage file maybe?
> 
> I am committing some changes to the enum generation, after that (and a
> successfull build) I will close the issue.
> 
> gr. Martin

I use Texo 0.1.0-201008031709

Even if I generate the model from the ecore without any annotationsmodel, I get this classifier problem.

I tried various setups and found something in the ecore :

<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="test"
    nsURI="http://test" nsPrefix="test">
  <eClassifiers xsi:type="ecore:EClass" name="Person">
    ...
  <eClassifiers xsi:type="ecore:EEnum" name="ContactType">
    <eLiterals name="ONE" value="0"/>
    <eLiterals name="TWO" value="1"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Contact">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="type" eType="#//ContactType"/>
  </eClassifiers>
</ecore:EPackage>

causes the problem at me, where:

<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="test"
    nsURI="http://test" nsPrefix="test">
  ...
  <eClassifiers xsi:type="ecore:EClass" name="Contact">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="type" eType="#//ContactType"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EEnum" name="ContactType">
    <eLiterals name="ONE" value="0"/>
    <eLiterals name="TWO" value="1"/>
  </eClassifiers>
</ecore:EPackage>

makes no problem. No idea why. 

But another try with a new ecore example failed with the same exception. No matter on which position the enum is defined. So I couldn't verify this problem.

Regards,
Mark
Comment 15 Martin Taal CLA 2010-09-16 14:29:30 EDT
I published a new build a few mins back. Closing this issue.

The classifier problem remains strange, I can't reproduce it myself. Let's discuss this issue further at the other bugzilla you entered.

gr. Martin