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: 6
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: 1081
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: 4426
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: 6
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: 429
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 message
Robert Wild is currently offline Robert Wild
Messages: 26
Registered: August 2012
Junior 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.
Previous Topic:Question on cross-referencing and scoping
Next Topic:2-step generating
Goto Forum:
  


Current Time: Sat May 25 23:10:28 EDT 2013

Powered by FUDForum. Page generated in 0.01637 seconds