Accessing Enum values compliant with iModel [message #1857552] |
Wed, 15 February 2023 01:11 |
|
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 |
|
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 |
|
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 #1857615 is a reply to message #1857614] |
Thu, 16 February 2023 23:29 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02858 seconds