Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » problem with using enums as optional elements
problem with using enums as optional elements [message #760200] Thu, 01 December 2011 10:26 Go to next message
Joerg Thiemer is currently offline Joerg Thiemer
Messages: 8
Registered: July 2010
Junior Member
Hi,

I have a problem with the use of enums and processing the grammar. I'm not using XTend, I'm using java directly.

My dsl is like this

...
ItemVisualization:
'item' id=ID
'type' dbType=DBTYPE
('caption' caption=STRING)?
('align' align=ALIGNTYPE)?
...
;

enum ALIGNTYPE :
H2 = 'h2' |
B2 = 'b2' |
K1 = 'k1'
...

While processing the DSL I can use the question ...getCaption()!=null ... to test whether the optional element caption is used or not.
In the case of align this did'nt work, getAlign() is not null and getAlign().getLiteral() deliver the first value of the enum ('h2').

How can I check wether th optional align was used or not?

Thanks

Re: problem with using enums as optional elements [message #760210 is a reply to message #760200] Thu, 01 December 2011 10:46 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1151
Registered: July 2009
Senior Member
Hi,

at least 2 possibilities:
-you can introduce an artificial enum (default value) UNSET (first of the list
-you can bind the align keyword to a boolean feature (isAlignSet?='align' align=...)

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: problem with using enums as optional elements [message #760235 is a reply to message #760210] Thu, 01 December 2011 11:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6230
Registered: July 2009
Senior Member
Hi,

you can use a manually maintained metamodel with an unsettable eattribute
maybe you can use the metamodel postprocessor to make the eattribute unsettable too

~Christian
Re: problem with using enums as optional elements [message #760358 is a reply to message #760200] Fri, 02 December 2011 01:33 Go to previous messageGo to next message
Joerg Thiemer is currently offline Joerg Thiemer
Messages: 8
Registered: July 2010
Junior Member
Hi,

Cool!
Thank you for your quick reply.

I tried the binding to a boolean feature and it works fine.

Joerg
Re: problem with using enums as optional elements [message #760428 is a reply to message #760358] Fri, 02 December 2011 05:55 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte Boersma
Messages: 433
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
You should be able to use the EObject#isSet method as well. Something like this should work (untested):
instance.eIsSet(instance.eClass().getEStructuralFeature("caption"))



Re: problem with using enums as optional elements [message #1016985 is a reply to message #760428] Fri, 08 March 2013 08:34 Go to previous messageGo to next message
Robert Wild is currently offline Robert Wild
Messages: 33
Registered: August 2012
Member
Meinte Boersma wrote on Fri, 02 December 2011 05:55
You should be able to use the EObject#isSet method as well. Something like this should work (untested):
instance.eIsSet(instance.eClass().getEStructuralFeature("caption"))



This doesn't work for the first element in the enum. eIsSet will return false, if the first enum value is specified.

I used UNSET as first element in the list and hid it from ContentAssist.
Re: problem with using enums as optional elements [message #1062412 is a reply to message #760210] Fri, 07 June 2013 10:45 Go to previous messageGo to next message
Sasa Kartalija is currently offline Sasa Kartalija
Messages: 1
Registered: June 2013
Junior Member
I have similar problem, but my grammar dont have some keyword before enum Memory, which signal me that Memory is used.

My dsl grammar is:

...
Rule:
name=ID memory=Memory? int=INT
...
;

enum Memory:
xm = 'XM' | pm = 'PM' | ym = 'YM'
;

Thanks,
Sale
Re: problem with using enums as optional elements [message #1062504 is a reply to message #1062412] Sat, 08 June 2013 03:00 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6230
Registered: July 2009
Senior Member
Hi the unsettable Solution does not Need keywords
Previous Topic:Custom Syntax Error Recovery
Next Topic:Using a File located in workspace during Validation process
Goto Forum:
  


Current Time: Fri Aug 29 18:33:58 EDT 2014

Powered by FUDForum. Page generated in 0.02013 seconds