Home » Modeling » EMF » Best Practice: Get EEnumLiteral from Enumerator(Ask for best practice)
| | |
Re: Best Practice: Get EEnumLiteral from Enumerator [message #1715345 is a reply to message #1715332] |
Sun, 22 November 2015 14:54 |
Philipp Kutter 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 |
Ed Merks 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/
|
|
|
Goto Forum:
Current Time: Fri Apr 19 15:27:39 GMT 2024
Powered by FUDForum. Page generated in 0.01937 seconds
|