Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set enum reference with default value = null in ecore and gen model?

I have an Eclass Vehicle which has an enum attribute BreakType breakType.

BreakType is defined in the same Ecore model as:

BreakType{
    DRUM(0), DISC(1), BLADE(2)
}

I want to set attribute breakType default to null. for that I set following properties for breakType attribute->

DefaultLiteralValue: // it's blank
Unsettable: True

Properties of BreakType enum
Default Value : DRUM=0 // this is shown in editor UI even If i remove it from xml.

What I am getting after generating gen-model and code out of it is

BreakType breakType = DRUM // attribute set with default value

How can I set it to null, by default?

like image 302
roul ze Avatar asked Nov 12 '22 22:11

roul ze


1 Answers

I don't think you can. If you fail to provide a default value through the defaultValueLiteral property EMF automatically picks a value appropriate to the type of the attribute. For an enumerated type, it is the first literal value that it defines.

You can always modify the generated code yourself. Or maybe you should make use of the methods generated to provide the unsettable functionality:

void unsetAttribute();
boolean isSetAttribute();

and check for the unset state instead of the null value.

like image 97
José M. Benítez Avatar answered Dec 31 '22 13:12

José M. Benítez