Skip to main content



      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
Eclipse UserFriend
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
Eclipse UserFriend
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
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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 Jul 25 00:26:43 EDT 2025

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

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

Back to the top