Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Test for an undefined enumeration in OCL(Test for an undefined enumeration in OCL)
[Acceleo] Test for an undefined enumeration in OCL [message #869962] Sat, 05 May 2012 08:48 Go to next message
CRASNIER Stéphane is currently offline CRASNIER StéphaneFriend
Messages: 13
Registered: May 2012
Junior Member
First of all : thanks for the support !

My problem : I want to simply test if an "enumerated" attribute is defined or not.

Let's say I have :

    - an EnumValues enumeration with 2 values VALUE1 and VALUE2
    - an EObject object with an optional attribute value of type EnumValues


I would have expected to test the value existence thanks to this expression :
object.value.oclIsUndefined()


But this expression always returns true as the value attribute seems to be initialized with the first value of the enumeration. The only bypass way I've found is to not declare EnumValues as an Enum but as an EObject. Then the oclIsUndefined() method returns false when the attribute is not set in the model. BTW my model is generated thanks to Xtext.

It seems to be a stupid question but I'm not able to find the answer on Google, in the OCL specification or in the Acceleo resources.

The only material I've found says that the only way to achieve this is to use the isUndefined or the more general isUndefined('value') OCL helper methods. But I'm not able to decline this in the Acceleo environnement.

Do you have any idea ?

Thanks in advance for your reply !

Stéphane
Re: [Acceleo] Test for an undefined enumeration in OCL [message #869967 is a reply to message #869962] Sat, 05 May 2012 09:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I think that you're in a gap between OMG (UML/EMOF) behaviour and Ecore.

Ecore allows optional enumerations, EMOF does not.

If you want an 'optional' enumeration, it is better to add an UNDEFINED
enumeration value. After all when you think about it why omit this valid
state.

Regards

Ed Willink

On 05/05/2012 09:48, CRASNIER Stéphane wrote:
> First of all : thanks for the support !
>
> My problem : I want to simply test if an "enumerated" attribute is
> defined or not.
>
> Let's say I have :
>
> - an EnumValues enumeration with 2 values VALUE1 and VALUE2
> - an EObject object with an optional attribute value of type EnumValues
>
>
> I would have expected to test the value existence thanks to this
> expression :
> object.value.oclIsUndefined()
>
> But this expression always returns true as the value attribute seems
> to be initialized with the first value of the enumeration. The only
> bypass way I've found is to not declare EnumValues as an Enum but as
> an EObject. Then the oclIsUndefined() method returns false when the
> attribute is not set in the model. BTW my model is generated thanks to
> Xtext.
>
> It seems to be a stupid question but I'm not able to find the answer
> on Google, in the OCL specification or in the Acceleo resources.
>
> The only material I've found says that the only way to achieve this is
> to use the isUndefined or the more general isUndefined('value') OCL
> helper methods. But I'm not able to decline this in the Acceleo
> environnement.
>
> Do you have any idea ?
>
> Thanks in advance for your reply !
>
> Stéphane
>
Re: [Acceleo] Test for an undefined enumeration in OCL [message #870073 is a reply to message #869967] Sun, 06 May 2012 06:51 Go to previous messageGo to next message
CRASNIER Stéphane is currently offline CRASNIER StéphaneFriend
Messages: 13
Registered: May 2012
Junior Member
Hi Edward !

Thank you very much for your reply !

Effectively it was one of my idea : setting the first value of the enumeration to an undefined one.

But I see one drawback to this in my context : how to be sure that this first value will be used to initialize the attribute by Xtext... Even if it seems to be the case after having tested this tip.

Well... I may have to dive in the Xtext code to see how it handles optionnal enumeration value...Smile

Again : thanks for your reply !

Stéphane
Re: [Acceleo] Test for an undefined enumeration in OCL [message #870080 is a reply to message #870073] Sun, 06 May 2012 08:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

have a look at the Xtext documentation:

Quote:

Please note, that Ecore does not support unset values for enums. If you define a grammar like

Element: "element" name=ID (value=SomeEnum)?;

with the input of

element Foo

the resulting value of the element Foo will hold the enum value with the internal representation of 0 (zero). When generating the EPackage from your grammar this will be the first literal you define. As a workaround you could introduce a dedicated none-value or order the enums accordingly. Note that it is not possible to define an enum literal with an empty textual representation.

You can overcome this by modifying the infered Ecore model through a model to model transformation. However, instead of post processing, an explicitly imported metamodel is recommend.



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Acceleo] Test for an undefined enumeration in OCL [message #870106 is a reply to message #870080] Sun, 06 May 2012 14:47 Go to previous message
CRASNIER Stéphane is currently offline CRASNIER StéphaneFriend
Messages: 13
Registered: May 2012
Junior Member
Hi Christian !

Shame on me !Smile

I would have had to have a better look at the Xtext documentation. Thanks for having brought me this point to light.

So as Edward wrote, I'm gonna resign myself to creating this "undefined" enumeration value.

Thanks again.

Stéphane
Previous Topic:[Galileo, XPAND] Loop using the expression FOREACH
Next Topic:[Acceleo] How to run Acceleo from java file
Goto Forum:
  


Current Time: Tue Apr 23 07:38:39 GMT 2024

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

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

Back to the top