[Accelleo] Access EEnumLiteral's EAnnotation [message #1699452] |
Wed, 24 June 2015 12:19  |
Le Chau Nguyen Messages: 19 Registered: August 2012 |
Junior Member |
|
|
Hi Everyone,
This is my model:

FootballClub, DancingClub etc are EClass.
FootballClubType, DancingClubType are EENum
And USClub, JapanClub etc. are their EENumLiteral
Normally I can get EAnnotation of EClass like FootballClub, DancingClub by this kind of query:
[self.target.eClass().getEAnnotation('info').details->first().value/]
But, I cannot apply the similar query to get EAnnotation of EENumLiteral or EENum type. This is the query I tried to get EENum's EAnnotation:
[self.target.eGet('clubType').oclAsType(Club::FootballClubType).getEAnnotation('info').details->first().value/]
The error is: "cannot find operation (getEAnnotation(String)) for the type (FootballClubType)"
I believe after casting by oclAsType, I have the FootballClubType which is EENum, so I can get its EAnnotation as I get from EClass. Because both EENum and EClass realizes the interface EModelElement interface that provide "getEAnnotation" operation.
So maybe I have done something wrong?
And how to access to EENumLiteral's EAnnotation? for example I want to read EAnnotation of "USClub".
Is this something like:
[self.target.eGet('clubType').oclAsType(Club::FootballClubType).eGet('USClub').oclAsType(ecore::EENumLiteral).getEAnnotation('info').details->first().value/] ? Are there any way that avoid hard-code "USClub" in the query since clubType already have Literal information?
I have been stuck on this problem for long time and may have to re-design the model to avoid EENum by using EClass only. That's very painful. Please help me if you have any idea, thank you.
[Updated on: Wed, 24 June 2015 12:24] Report message to a moderator
|
|
|
Re: [Accelleo] Access EEnumLiteral's EAnnotation [message #1699460 is a reply to message #1699452] |
Wed, 24 June 2015 12:49   |
Ed Willink Messages: 7635 Registered: July 2009 |
Senior Member |
|
|
Hi
There are a variety of complexities regarding EEnumLiterals whose
instances are Enumerator and do not always have a reflective model
content such as eClass(). This may be contributing to your confusion,
but most of your problem seems to be a misunderstanding of meta-levels.
Assuming that by "FootballClubType, DancingClubType are EENum" you mean
that they are modelled by, rather than specialize/derive from.
FootballClubType is therefore a user type and so has no getEAnnotation
method; just as Acceleo shows you.
Similarly FootballClub has no getEAnnotation method until you invoke
eClass() to climb a meta-level
If you want to access the metamodel EAnnotation on FootballClubType you
must use eClass().
(Or if you want to access the model EAnnotation on FootballClubType you
must define FootballClubType as a derivation of EModelElement; this is
usually a bad idea.)
Regards
Ed Willink
On 24/06/2015 13:19, Le Chau Nguyen wrote:
> Hi Everyone,
>
> This is my model:
> FootballClub, DancingClub etc are EClass.
> FootballClubType, DancingClubType are EENum
> And USClub, JapanClub etc. are their EENumLiteral
>
> Normally I can get EAnnotation of EClass like FootballClub,
> DancingClub by this kind of query:
> [self.target.eClass().getEAnnotation('info').details->first().value/]
>
> But, I cannot apply the similar query to get EAnnotation of
> EENumLiteral or EENum type. This is the query I tried to get EENum's
> EAnnotation:
> [self.target.eGet('clubType').oclAsType(Club::FootballClubType).getEAnnotation('info').details->first().value/]
>
>
> The error is: "cannot find operation (getEAnnotation(String)) for the
> type (FootballClubType)"
>
> I believe after casting by oclAsType, I have the FootballClubType
> which is EENum, so I can get its EAnnotation as I get from EClass.
> Because both EENum and EClass realizes the interface EModelElement
> interface that provide "getEAnnotation" operation.
>
> So maybe I have done something wrong?
> And how to access to EENumLiteral's EAnnotation? for example I want to
> read EAnnotation of "USClub".
> Is this something like:
> [self.target.eGet('clubType').oclAsType(Club::FootballClubType).eGet('USClub').oclAsType(ecore::EENumLiteral).getEAnnotation('info').details->first().value/]
> ? Any way that avoid hard-code "USClub" in the query since clubType
> should already have Literal information?
>
> I have been stuck on this problem for long time and may have to
> re-design the model to avoid EENum. That's very painful. Please help
> me if you have any idea, thank you.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02173 seconds