Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Accessing Enum values compliant with iModel(access via Ecore references is brittle)
Accessing Enum values compliant with iModel [message #1857552] Wed, 15 February 2023 01:11 Go to next message
Jörn Guy Süß is currently offline Jörn Guy SüßFriend
Messages: 320
Registered: July 2009
Location: Anstead, Brisbane, Queens...
Senior Member

Below is code we use to access the enumeration value list on an EEnum.
This is due to the fact that we do not seem to be able to get access to an EEnum as a type in its on right.

The issue we have with this code is that it is brittle and implementation-specific.

var enum = Enum#value.eEnum;
for (val in enum.eLiterals) {
  internalContext.name.println();
}


It is brittle because the access is pinned to a specific enumeration value. If that value is changed, the code will fail, despite the fact that the intended access is reflective.

It is implementation-specific because it uses an Ecore-based feature to perform the navigation, which Epsilons IModel does not mandate, as the notion of type and hence Enum are deliberately not defined.

Is there a safer and more succinct way to write this traversal? How can we get access to an EEnum directly?
Re: Accessing Enum values compliant with iModel [message #1857583 is a reply to message #1857552] Wed, 15 February 2023 23:49 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Jörn Guy,

I can't think of a better way to achieve this at the moment I'm afraid. I guess we could add a public getEnumeration(String name) method to AbstractEmfModel so that one could use M.getEnumeration("Enum").eLiterals, but this doesn't look very elegant. Any thoughts would be more than welcome.

Thanks,
Dimitris
Re: Accessing Enum values compliant with iModel [message #1857587 is a reply to message #1857583] Thu, 16 February 2023 00:54 Go to previous messageGo to next message
Jörn Guy Süß is currently offline Jörn Guy SüßFriend
Messages: 320
Registered: July 2009
Location: Anstead, Brisbane, Queens...
Senior Member

How about having a specific Syntax for obtaining the set of enums that is based on the existing Syntax? I'm thinking of something like

var enumValues : OrderedSet<Enum>= Enum#*;


This would block the name * as a name for an enum, but for that we would have the usual EOL escape:

var enumAsterisk : OrderedSet<WildcardEnum>= WildcardEnum#`*`;


This requires a change to the parser but allows the mechanism in general for all EMC rather than just the EMF scope.

This seems sensible because enumerations are such a common concept.
Re: Accessing Enum values compliant with iModel [message #1857610 is a reply to message #1857587] Thu, 16 February 2023 19:57 Go to previous messageGo to next message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 242
Registered: October 2009
Location: Mexico
Senior Member

Hi,

Perhaps add an "getLiterals()" method to Enumerations via an operation contirbutor?


Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
Re: Accessing Enum values compliant with iModel [message #1857614 is a reply to message #1857610] Thu, 16 February 2023 22:01 Go to previous messageGo to next message
Jörn Guy Süß is currently offline Jörn Guy SüßFriend
Messages: 320
Registered: July 2009
Location: Anstead, Brisbane, Queens...
Senior Member

Would that mean you needed the contributor active to have this? I feel given that the core language acknowledges the existence of enum values, should it not also acknowledge the value set. Or is EOL deliberately opinionated about users not knowing the extent of the set?

Java has
getEnumConstants().

[Updated on: Thu, 16 February 2023 22:08]

Report message to a moderator

Re: Accessing Enum values compliant with iModel [message #1857615 is a reply to message #1857614] Thu, 16 February 2023 23:29 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

I think that going forward, we should just treat enumerations like first-class types so that we can also use them as variable and parameter types. When this is done, one should be able to access all literals of enumeration E using something like E.literals.

Thanks,
Dimitris
Re: Accessing Enum values compliant with iModel [message #1857726 is a reply to message #1857615] Thu, 23 February 2023 05:08 Go to previous message
Jörn Guy Süß is currently offline Jörn Guy SüßFriend
Messages: 320
Registered: July 2009
Location: Anstead, Brisbane, Queens...
Senior Member

That would be really good. I just did not want to push the enum concept into EMC when it was deliberately meant to avoid specifics. I agree that Enums are very common.
Previous Topic:Resolve reference between models with ETL
Next Topic:Delegating to EOL from EMF
Goto Forum:
  


Current Time: Thu Apr 25 04:47:05 GMT 2024

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

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

Back to the top