Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with Enums in Xcore-XTEXT(Problem with Enums in Xcore)
icon5.gif  Problem with Enums in Xcore-XTEXT [message #1125175] Fri, 04 October 2013 08:26 Go to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
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 Smile


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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31251
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 :)
icon5.gif  Re: Problem with Enums in Xcore [message #1125206 is a reply to message #1125193] Fri, 04 October 2013 09:13 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hello Ed,
First of all thanks for your reply Smile
I apologize for typing it wrongly, I wanted to type record and typed it as recore.

Just I wanted to convey that I have a List of objects and this enum is one property of that object.

And could you please give me a hint where can I make that EAttribute Unsettable true.

Thanks in advance Smile


Arshad
Re: Problem with Enums in Xcore [message #1125227 is a reply to message #1125206] Fri, 04 October 2013 09:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
class X {
	unsettable String a 
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon7.gif  Re: Problem with Enums in Xcore [message #1125280 is a reply to message #1125227] Fri, 04 October 2013 10:51 Go to previous message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hello Ed,
I tried your suggestion and it works for me.
Thanks a lot for your help Smile


Arshad
Previous Topic:Performance Issues
Next Topic:Problem generating RCP with Xtext
Goto Forum:
  


Current Time: Sat Jul 11 05:03:28 GMT 2020

Powered by FUDForum. Page generated in 0.03284 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top