Skip to main content


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 15:26 Go to next message
Joerg Thiemer is currently offline Joerg ThiemerFriend
Messages: 10
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 15:46 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
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 16:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: problem with using enums as optional elements [message #760358 is a reply to message #760200] Fri, 02 December 2011 06:33 Go to previous messageGo to next message
Joerg Thiemer is currently offline Joerg ThiemerFriend
Messages: 10
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 10:55 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
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 13:34 Go to previous messageGo to next message
Robert Wild is currently offline Robert WildFriend
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 14:45 Go to previous messageGo to next message
Sasa Kartalija is currently offline Sasa KartalijaFriend
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 07:00 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi the unsettable Solution does not Need keywords

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Custom Syntax Error Recovery
Next Topic:Using a File located in workspace during Validation process
Goto Forum:
  


Current Time: Tue Apr 16 22:57:26 GMT 2024

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

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

Back to the top