Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Best Practice: Get EEnumLiteral from Enumerator(Ask for best practice)
Best Practice: Get EEnumLiteral from Enumerator [message #1715326] Sun, 22 November 2015 08:45 Go to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
I already read 424631

Just for confirmation:
Given an Enumerator Y_e and one of its literals x_e, generated from an ECore model that contains an EENumLiteral X_ee inside EENum Y_ee, the best practice to get X_ee from X_e is:

EEnum Y_ee = ....
Y_e x_e= .....
EENumLiteral X_ee = Y_ee.geteenumliteralByLiteral(x_e.getLiteral())

I will try this out. Forgive me if I made an error.

One question: Is there nothing in EEnum like a

getEEnumLiteralByEnumerator(Enumerator e)

It just sound strange, we have to go through the string...
Re: Best Practice: Get EEnumLiteral from Enumerator [message #1715331 is a reply to message #1715326] Sun, 22 November 2015 10:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Philipp,

Comments below.

On 22/11/2015 9:45 AM, Philipp W. Kutter wrote:
> I already read 424631
Is this a bug number? How is this related?
>
> Just for confirmation:
> Given an Enumerator Y_e and one of its literals x_e, generated from an
> ECore model that contains an EENumLiteral X_ee inside EENum Y_ee, the
> best practice to get X_ee from X_e is:
>
> EEnum Y_ee = ....
> Y_e x_e= .....
> EENumLiteral X_ee = Y_ee.geteenumliteralByLiteral(x_e.getLiteral())
>
> I will try this out. Forgive me if I made an error.
>
> One question: Is there nothing in EEnum like a
> getEEnumLiteralByEnumerator(Enumerator e)
>
> It just sound strange, we have to go through the string...
It's never been required anywhere to look up the literal by enumerator
instance. I'm not sure how this need arises, i.e., how you know which
EEnum to search for the enumerator?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Best Practice: Get EEnumLiteral from Enumerator [message #1715332 is a reply to message #1715326] Sun, 22 November 2015 11:02 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

424631? wrong number ?

It does seem very unfortunate that the Java implementation of an
EnumerationLiteral provides the only modeled Ecore object that sometimes
loses its reflective context. But that is the way it is.

In the worst case, you need to search all eClass() in your ResourceSet
to identify all the EPakages within which you can locate the EEnums and
so find the EEnumerationLiteral for a given Enumerator. Worth building a
cache so that you only do it once.

Regards

Ed Willink

On 22/11/2015 08:45, Philipp W. Kutter wrote:
> I already read 424631
>
> Just for confirmation:
> Given an Enumerator Y_e and one of its literals x_e, generated from an
> ECore model that contains an EENumLiteral X_ee inside EENum Y_ee, the
> best practice to get X_ee from X_e is:
>
> EEnum Y_ee = ....
> Y_e x_e= .....
> EENumLiteral X_ee = Y_ee.geteenumliteralByLiteral(x_e.getLiteral())
>
> I will try this out. Forgive me if I made an error.
>
> One question: Is there nothing in EEnum like a
> getEEnumLiteralByEnumerator(Enumerator e)
>
> It just sound strange, we have to go through the string...
Re: Best Practice: Get EEnumLiteral from Enumerator [message #1715345 is a reply to message #1715332] Sun, 22 November 2015 14:54 Go to previous messageGo to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
Referenced post: https://www.eclipse.org/forums/index.php?t=msg&th=135267&goto=424631&#msg_424631

RE: Ed W.: yes, unfortunate.

RE: Ed M.: to answer your question:

Given an EAttribute a of type Y_ee, being derived, transient, volatile, and changeable. In the generated setter, you have setA(newY: Y_e)

Now, if you want inside this setter operation write code that translates the Y_e into its corresponding EEnumLiteral, then you need to do exactly what I wrote above:

EENumLiteral newYasEEnumLiteral = MYPACKAGE.Literals.Y.geteenumliteralByLiteral(newY.getLiteral())

Thus you know the EEnum from the context, and can get it in the package, but it misses a way to then get the corresponding EEnumLiteral without going through the string.

Why not simply add an option, that generates code, where instead of the special "Enumerators" from Java, we have instance of a class, inheriting from EEnumLiteral, or some other way to make sure the reflective context is not lost.

Re: Best Practice: Get EEnumLiteral from Enumerator [message #1715350 is a reply to message #1715345] Sun, 22 November 2015 16:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
MYPACKAGE.Literals.Y.getEEnumLiterals().get(newY.ordinal()) works too
and is the most efficient; no iteration to find a match.

On 22/11/2015 3:54 PM, Philipp W. Kutter wrote:
> Referenced post:
> https://www.eclipse.org/forums/index.php?t=msg&th=135267&goto=424631&#msg_424631
>
> RE: Ed W.: yes, unfortunate.
> RE: Ed M.: to answer your question:
>
> Given an EAttribute a of type Y_ee, being derived, transient,
> volatile, and changeable. In the generated setter, you have setA(newY:
> Y_e)
>
> Now, if you want inside this setter operation write code that
> translates the Y_e into its corresponding EEnumLiteral, then you need
> to do exactly what I wrote above:
>
> EENumLiteral newYasEEnumLiteral =
> MYPACKAGE.Literals.Y.geteenumliteralByLiteral(newY.getLiteral())
>
> Thus you know the EEnum from the context, and can get it in the
> package, but it misses a way to then get the corresponding
> EEnumLiteral without going through the string.
>
> Why not simply add an option, that generates code, where instead of
> the special "Enumerators" from Java, we have instance of a class,
> inheriting from EEnumLiteral, or some other way to make sure the
> reflective context is not lost.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:CompoundCommand.appendAndExecute question
Next Topic:[CDO] Usage of MySQL adapter with InnoDB
Goto Forum:
  


Current Time: Fri Apr 19 15:27:39 GMT 2024

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

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

Back to the top