Problem with Enums in Xcore-XTEXT [message #1125175] |
Fri, 04 October 2013 08:26 |
|
Hello all,
I am using xcore as Metamodel for my xtext Grammar.
I have some enum as:
enum Sample {
value1
value2
value3
}
and xtext Grammar as:
enum EMSFunctionHdlrType:
value1 |
value2 |
value3
;
I am trying to fetch these values in the Generator. If these values are typed in the editor then it will return me the correct value i.e. value1,value2 or value3.
But if not typed for a recore, it returns by default the first value in the enum i.e. value1.
How can I avoid it?
Thanks in advance
Arshad
[Updated on: Fri, 04 October 2013 08:36] Report message to a moderator
|
|
|
Re: Problem with Enums in Xcore [message #1125193 is a reply to message #1125175] |
Fri, 04 October 2013 08:51 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Arshad,
Comments below.
On 04/10/2013 10:27 AM, Arshad Adavani wrote:
> Hello all,
> I am using xcore as Metamodel for my xtext Grammar.
> I have some enum as:
> enum Sample {
> value1
> value2
> value3
> }
>
> and xtext Grammar as:
> enum EMSFunctionHdlrType:
> value1 |
> value2 |
> value3
> ;
>
> I am trying to fetch these values in the Generator. If these values
> are typed in the editor then it will return me the correct value i.e.
> value1,value2 or value3.
> But if not typed for a recore,
What's a recore?
> it returns by default the first value in the enum i.e. value1.
I'm not sure I follow the question, but keep in mind that in EMF,
enumerations are treated like primitive types, so an EAttribute of type
EEnum will never return null and by default will return the first enum
literal (just as an EAttribute of type EInt will by default return 0).
In both cases, if you want to distinguish the state of the model to
detect when the feature has been explicitly set verses when the feature
is in the default state, you can make that EAttribute Unsettable true.
Then your generated API will have getX, setX, isSetX, and unsetX, so you
can tell when isSetX is true, the value was present in the source, and
when it's false, the value is the default.
> How can I avoid it?
>
> Thanks in advance :)
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03210 seconds