Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » new generic Datatype not generated properly
new generic Datatype not generated properly [message #426122] Tue, 16 December 2008 22:16 Go to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Hi all and Ed and Christian ;)

I have the same need as Andreas, mentioned below that is an EnumSet type
and I have tried Christian proposal.
I have created a new EDataType in my Ecore metamodel named :
ActionTypeEnumSet
with the property
instanceTypeName=java.util.EnumSet<ActionType>
where ActionType is a EEnum.
The problem is the .genmodel considers my ActionTypeEnumSet as a
java.util.EnumSet<Object> ??????
This generates a model that does not compile.

Any ideas ??

Thank you.

SeB.




-------------------------------------------------------
Hi, Andreas,


Only Ed can speak to plans, but you can define an EDataType with
java.util.EnumSet as the "instanceTypeName." You can even add the E
generic type parameter (remember to enable Generics in the Ecore Editor
menu).

Then, it's just a matter of implementing the
createFromString/convertToString methods in your generated FactoryImpl to
serialize the enum-set values.

HTH,


Christian


Andreas Mayer wrote:

In my model, I have several enums that can be combined, for example,
privileges such as READ, WRITE, and DELETE. Therefore, some classes have
multi-valued attributes of such enums.

EMF converts an EEnum into a Java enum, but uses an EList for a
multi-valued enum attribute. I would prefer to use an EnumSet instead.
Aside from the more efficient implementation, EnumSet.equals() ignores the
order in which the values have been added.

Is there a way to force the code generator to use EnumSet instead of
EList here? Are there any plans to add some sp ecial handling for
multi-valued enum attributes?

Andreas
Re: new generic Datatype not generated properly [message #426123 is a reply to message #426122] Tue, 16 December 2008 22:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30993
Registered: July 2009
Senior Member
SeB,

Comments below.

seb.fr wrote:
> Hi all and Ed and Christian ;)
>
> I have the same need as Andreas, mentioned below that is an EnumSet type
> and I have tried Christian proposal.
> I have created a new EDataType in my Ecore metamodel named :
> ActionTypeEnumSet
> with the property instanceTypeName=java.util.EnumSet<ActionType>
> where ActionType is a EEnum.
You need ActionType to be a fully qualified name, e.g.,
java.util.EnumSet<org.example.action.ActionType>
> The problem is the .genmodel considers my ActionTypeEnumSet as a
> java.util.EnumSet<Object> ??????
> This generates a model that does not compile.
>
> Any ideas ??
>
> Thank you.
>
> SeB.
>
>
>
>
> -------------------------------------------------------
> Hi, Andreas,
>
>
> Only Ed can speak to plans, but you can define an EDataType with
> java.util.EnumSet as the "instanceTypeName." You can even add the E
> generic type parameter (remember to enable Generics in the Ecore
> Editor menu).
>
> Then, it's just a matter of implementing the
> createFromString/convertToString methods in your generated FactoryImpl
> to serialize the enum-set values.
>
> HTH,
>
>
> Christian
>
>
> Andreas Mayer wrote:
>
> In my model, I have several enums that can be combined, for
> example, privileges such as READ, WRITE, and DELETE. Therefore, some
> classes have multi-valued attributes of such enums.
>
> EMF converts an EEnum into a Java enum, but uses an EList for a
> multi-valued enum attribute. I would prefer to use an EnumSet instead.
> Aside from the more efficient implementation, EnumSet.equals() ignores
> the order in which the values have been added.
>
> Is there a way to force the code generator to use EnumSet instead
> of EList here? Are there any plans to add some sp ecial handling for
> multi-valued enum attributes?
>
> Andreas
>
Re: new generic Datatype not generated properly[RESOLVED]... but [message #426168 is a reply to message #426123] Wed, 17 December 2008 22:33 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Thank Ed,

that worked well, but that means that when you create the ecore metamodel
you hought to know with package name you are going to use for the
generated code.
And therefore if I decide to change the package the model is generated in,
then I need to go back to ly ecore metamodel and change it again?

that seems akward to me.

Thanks anyway.

SeB.


Ed Merks wrote:

> SeB,

> Comments below.

> seb.fr wrote:
>> Hi all and Ed and Christian ;)
>>
>> I have the same need as Andreas, mentioned below that is an EnumSet type
>> and I have tried Christian proposal.
>> I have created a new EDataType in my Ecore metamodel named :
>> ActionTypeEnumSet
>> with the property instanceTypeName=java.util.EnumSet<ActionType>
>> where ActionType is a EEnum.
> You need ActionType to be a fully qualified name, e.g.,
> java.util.EnumSet<org.example.action.ActionType>
>> The problem is the .genmodel considers my ActionTypeEnumSet as a
>> java.util.EnumSet<Object> ??????
>> This generates a model that does not compile.
>>
>> Any ideas ??
>>
>> Thank you.
>>
>> SeB.
>>
Re: new generic Datatype not generated properly[RESOLVED]... but [message #426171 is a reply to message #426168] Thu, 18 December 2008 01:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30993
Registered: July 2009
Senior Member
SeB,

Comments below.


seb.fr wrote:
> Thank Ed,
>
> that worked well, but that means that when you create the ecore
> metamodel you hought to know with package name you are going to use
> for the generated code.
Unfortunately because it's purely a string-based representation, yes,
that's true. An alternative is to define an EDataType for just
java.util.EnumSet and define it to have a ETypeParameter; then you could
use an EGenericType to reference it, and use another EGenericType as a
eTypeArgument to references the EEnum.
> And therefore if I decide to change the package the model is generated
> in, then I need to go back to ly ecore metamodel and change it again?
Yes, unless you take the alternative approach; that approach requires
defining serialization in a more general way though, but that's probably
fine...
>
> that seems akward to me.
Almost as awkward as EnumSet<E extends Enum<E>> :-P Doesn't that make
your brain hurt?
>
> Thanks anyway.
>
> SeB.
>
>
> Ed Merks wrote:
>
>> SeB,
>
>> Comments below.
>
>> seb.fr wrote:
>>> Hi all and Ed and Christian ;)
>>>
>>> I have the same need as Andreas, mentioned below that is an EnumSet
>>> type
>>> and I have tried Christian proposal.
>>> I have created a new EDataType in my Ecore metamodel named :
>>> ActionTypeEnumSet
>>> with the property instanceTypeName=java.util.EnumSet<ActionType>
>>> where ActionType is a EEnum.
>> You need ActionType to be a fully qualified name, e.g.,
>> java.util.EnumSet<org.example.action.ActionType>
>>> The problem is the .genmodel considers my ActionTypeEnumSet as a
>>> java.util.EnumSet<Object> ??????
>>> This generates a model that does not compile.
>>>
>>> Any ideas ??
>>>
>>> Thank you.
>>>
>>> SeB.
>>>
>
>
Previous Topic:Duplicate namespace error importing RuleML
Next Topic:[CDO]: CDOViewImpl#getResource on resource that does not exist throws InvalidURIException
Goto Forum:
  


Current Time: Sun Mar 29 16:19:35 GMT 2020

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

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

Back to the top