Enums Not Generated Correctly in Ecore
Specify a Brief Description
When converting an Umple file with an enum to an ecore file, the enum gets generated as an EData Type rather than as an EEnum.
Give the minimum Steps to Reproduce
- On Umple online, create a class diagram with an enum in one of the classes Possible Example:
class RootClass {
1 <@>- * Class1 classes1;
}
class Class1 {
unique Integer number;
enum ExampleEnum { Option1, Option2 }
;
ExampleEnum exampleEnum;
}
- Press "Generate" after selecting "Ecore" in the "Generate" tab
Describe the expected result that didn't happen
Expected a section in the ecore file with ExampleEnum as an EEnum
<eClassifiers xsi:type="ecore:EEnum" name="ExampleEnum"> <eLiterals name="Option1"/> <eLiterals name="Option2" value="1"/> </eClassifiers>
Actual Result
Instead, an EData Type is created:
<eClassifiers xsi:type="ecore:EDataType" name="ExampleEnum" instanceClassName="ExampleEnum" />
Labelling and Assigning
'ecore', 'Enum' 'EEnum'
The relevant code for the ecore generator can be found in directory
cruise.umple/src/generators/ecoregenerator
The class Generator_CodeEcore_Model defines class EcoreEnum at line 468 and is set up to output the correct code for Ecore enums.
The bug appears to be where EcoreEnum is instantiated ... currently only in line 222. In Umple enums were originally just degenerate state machines from a grammatical perspective without the keyword 'enum' and this notation still works. The Ecore generation code, which was written long ago, assumed this notation.
class X {
Status { FullTime, PartTime }
Status s;
}
If this notation is used the enum Status is output correctly .. but ALSO there is an incorrect output of an ecore:EDataType Status.
Part of the problem is that the Umple Ecore generator wasn't updated to use enums that use the enum keyword. The generator would have to be modified to identify these as in the following:
class X {
enum Status { FullTime, PartTime }
Status s;
}
or in the following
enum Status { FullTime, PartTime }
class X {
Status s;
}
The Ecore for the last simple example should (I think) be:
Correct code (probably)
<?xml version="1.0" encoding="UTF-8"?>
<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="model" nsURI="" nsPrefix="model">
<eClassifiers xsi:type="ecore:EEnum" name="Status">
<eLiterals name="FullTime" value="0" />
<eLiterals name="PartTime" value="1" />
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="X">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="s" eType="#//Status" />
</eClassifiers>
</ecore:EPackage>
Hello,
I noticed another issue with the Ecore generation. Compositions in Umple are generated as regular associations in Ecore instead of remaining compositions.
Thank you
@erica-d The student working on this issue (#2101) is almost done. I have noted your comment re compositions and have raised issue #2120 ... could you please provide the desired translation for the example I provided, in issue #2120, plus any other example you have in mind ... that would greatly help speed things up as the semester is rapidly coming to an end
It turns out that the two enum sytaxes both need supporting
Case 1: Will generate an enum AND a variable of the same name. This is the old syntax and the Ecore is OK for it.
class X {
status {a,b,c}
}
Case 2: Separates the enum declaration from the variable declaration, and is the case that does not work because the enum tests were created when the only syntax allowed in Umple was Case 1.
class Y {
enum newstatus {d,e,f}
newstatus vvv;
}
@erica-d ... I just merged a studnet's PR that fixes this issue. Could you verify that it is satisfactory? It is in the latest Umpleonline, and the command line version directly downloadable as https://umple.org/dl ... he is going to work on the other issue #2120 next. Should be done within a week (has a deadline)
@TimLethbridge I checked on UmpleOnline, it's looking good! Thank you for solving this issue!
Fixed by #2116