Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Retrieving EEnumLiteral attributes
Retrieving EEnumLiteral attributes [message #1861121] Thu, 21 September 2023 15:06 Go to next message
Alain Picard is currently offline Alain PicardFriend
Messages: 266
Registered: July 2009
Senior Member
I am looking at finding out the syntax to get one of the 3 attributes from an EEnum: name, literal and value.

In my current use case I need to retrieve the value integer to use for sorting elements.

I have no problem getting the enum itself: irel.depth which is of type: core::IndirectRelationshipDepth but I can't do: irel.depth.value or irel.depth.getValue() or ???

Thanks
Alain
Re: Retrieving EEnumLiteral attributes [message #1861122 is a reply to message #1861121] Thu, 21 September 2023 17:13 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
The simple answer is that you cannot because, in UML, an EnumerationLiteral is just a distinctively named element of an Enumeration. There are no literal or value aspects in UML. OCL is aligned with UML so OCL too has no literal or value aspects.

However, the Pivot OCL supports Ecore and reflection so it should be possible to use oclType() to make progress. Unfortunately, an EnumerationLiteral is a very deficient object so not much works reflectively.

You can get a form of literal value via e.g.

self.color.oclType().ownedLiterals->indexOf(self.color)


(This form of reflection is not supported by OMG OCL except that the exposition of flatten() in 11.7.2 requires it. Once supported, the spelling of e.g. ownedLiterals is open to design/dispute. The Pivot OCL tries to be a bit more rational than UML.)

https://bugs.eclipse.org/bugs/show_bug.cgi?id=582449 suggests that an EnumerationLiteral could conform to a new OclEnumerationLiteral type with literal/value properties.

Workaround: you can write a Java helper in some utilty class, but beware. An EEnumLiteral has multiple Ecore representations, one of which is 'too' lightweight forcing the Pivot OCL to cache the results of a total metamodel search to map lightweight to richer representations.
Re: Retrieving EEnumLiteral attributes [message #1861135 is a reply to message #1861122] Fri, 22 September 2023 09:59 Go to previous message
Alain Picard is currently offline Alain PicardFriend
Messages: 266
Registered: July 2009
Senior Member
Thanks Ed for the very informative reply, even if there is no obvious solution at the moment. As a workaround, since I had a single EClass using this enumeration, I added a transient, derived attribute to get the value for now. Other cases might have made this approach much more awkward, but at least for now the value is available.
Previous Topic:Calling out from OCL to Java
Next Topic:Failed to evaluate 'OclElement::allInstances() : Set(OclSelf)' for ...
Goto Forum:
  


Current Time: Sun May 05 14:27:30 GMT 2024

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

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

Back to the top