Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Generics in EMF
Generics in EMF [message #689855] Tue, 28 June 2011 14:01 Go to next message
tk  is currently offline tk Friend
Messages: 3
Registered: June 2011
Junior Member
Hi all,

I've searched the net for information about EMF Generics, but I've not found any information that addresses my question. So here goes...

(I've attached a picture with this post, so you should find the details there.)

Anyway, I've made a very simple Ecore model consisting of a package test
with three classes: Super, GenericClass and GenericClass2. The latter two classes have a type parameter. Each of these classes has an attribute typed with the type parameter variable. I've also made a dynamic instance of GenericClass with the associated properties pane.

My question is, what does generics in the Ecore model actually mean (as illustrated in this case) and how can I use this construction explicitly in my model? I made a dynamic instance of S and loaded this as a resource in the editor. Then I tried to add this instance as the value for attribute2 of GenericClass2. This didn't work. Is there a simple example that illustrates how the generic types of my model can be utilised?

(Some thoughts: the generic feature of the metamodel is not "visible" in my .xmi-file. Why not?)
Re: Generics in EMF [message #689954 is a reply to message #689855] Tue, 28 June 2011 16:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Comments below.

On 28/06/2011 7:01 AM, tk wrote:
> Hi all,
>
> I've searched the net for information about EMF Generics, but I've not found any information that addresses my question. So here goes...
No, there's not a lot of detail to find.
> (I've attached a picture with this post, so you should find the details there.)
Does this model validate? It seems problematic that E extends Super and
hence must be some type of EClass but it's used as the type of an
EAttribute which must be an EDataType. I think attribute2 needs to be
an EReference.
> Anyway, I've made a very simple Ecore model consisting of a package test
> with three classes: Super, GenericClass and GenericClass2. The latter two classes have a type parameter. Each of these classes has an attribute typed with the type parameter variable. I've also made a dynamic instance of GenericClass with the associated properties pane.
>
> My question is, what does generics in the Ecore model actually mean (as illustrated in this case) and how can I use this construction explicitly in my model?
Keep in mind that just as in Java, the underlying EMF runtime only uses
erased types. So while reflectively you can look at how generics are
used in the model, they have no impact on runtime behavior beyond what's
implied by their erasure. E.g., so attribute2 behaves as if it's of
type Super.
> I made a dynamic instance of S
Of Super you mean?
> and loaded this as a resource in the editor. Then I tried to add this instance as the value for attribute2 of GenericClass2. This didn't work.
No, I'm sure you meant for attribute2 to be an EReference.
> Is there a simple example that illustrates how the generic types of my model can be utilised?
>
> (Some thoughts: the generic feature of the metamodel is not "visible" in my .xmi-file. Why not?)
You've not set a value yet so there's nothing to serialize.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Generics in EMF [message #689986 is a reply to message #689855] Tue, 28 June 2011 17:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It's not an entirely simple example but it's real.

org.eclipse.ocl/model/OCL.ecore defines many generics
org.eclipse.ocl.ecore/model/OCLEcore.ecore specializes them

The corresponding src classes show all the generated code.

OCL.ecore is auto-generated from OCL.uml if you want to see even more.

Regards

Ed Willink




On 28/06/2011 16:01, tk wrote:
> Hi all,
>
> I've searched the net for information about EMF Generics, but I've not found any information that addresses my question. So here goes...
>
> (I've attached a picture with this post, so you should find the details there.)
>
> Anyway, I've made a very simple Ecore model consisting of a package test
> with three classes: Super, GenericClass and GenericClass2. The latter two classes have a type parameter. Each of these classes has an attribute typed with the type parameter variable. I've also made a dynamic instance of GenericClass with the associated properties pane.
>
> My question is, what does generics in the Ecore model actually mean (as illustrated in this case) and how can I use this construction explicitly in my model? I made a dynamic instance of S and loaded this as a resource in the editor. Then I tried to add this instance as the value for attribute2 of GenericClass2. This didn't work. Is there a simple example that illustrates how the generic types of my model can be utilised?
>
> (Some thoughts: the generic feature of the metamodel is not "visible" in my .xmi-file. Why not?)
Re: Generics in EMF [message #690299 is a reply to message #689986] Wed, 29 June 2011 10:27 Go to previous messageGo to next message
tk  is currently offline tk Friend
Messages: 3
Registered: June 2011
Junior Member
Thanks for your quick replies!

So, after modifying my Ecore model I'm now able to utilise the generic features in my .xmi-files. I also generated the model code to see how
things are implemented.

I've reviewed the OCL-models, but it's kinda difficult to get the overview, or said differently, the purpose of using generics. So my follow-up would have
to be: why would you like to use generics in the Ecore model? That is, what's the purpose and power of this feature, and what can be achieved?
Re: Generics in EMF [message #690478 is a reply to message #690299] Wed, 29 June 2011 14:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
I'm not sure if your question is specifically about why generics are
used in OCL or more generally. The general purpose of generics in Ecore
is the same as that for Java. You'd not be able to express in Ecore all
the things you can express directly in Java 5.0 unless we added the same
types of constructs as Java has to Ecore. Because we've implemented it
the same way as in Java, i.e., with the notion of erasures in mind, from
a dynamic EMF point of view, just as from a Java runtime reflection
point of view, there's effectively nothing to be gained. I.e., you
can't generally know what type of java.util.List you are dealing with
given just an instance of a List...


On 29/06/2011 3:27 AM, tk wrote:
> Thanks for your quick replies!
>
> So, after modifying my Ecore model I'm now able to utilise the generic
> features in my .xmi-files. I also generated the model code to see how
> things are implemented.
>
> I've reviewed the OCL-models, but it's kinda difficult to get the
> overview, or said differently, the purpose of using generics. So my
> follow-up would have to be: why would you like to use generics in the
> Ecore model? That is, what's the purpose and power of this feature,
> and what can be achieved?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Generics in EMF [message #690866 is a reply to message #690478] Thu, 30 June 2011 10:45 Go to previous messageGo to next message
tk  is currently offline tk Friend
Messages: 3
Registered: June 2011
Junior Member
Ah, I see. Thanks for the clarification!

Have a good day!

Re: Generics in EMF [message #690965 is a reply to message #690299] Thu, 30 June 2011 13:26 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi
> I've reviewed the OCL-models, but it's kinda difficult to get the
> overview, or said differently, the purpose of using generics.
Sorry for any confusion. I pointed you at the OCL models as functional
examples. The wisdom of the generics is certainly debatable; they are
being phased out. The purpose is to allow code sharing for the distinct
classes of the Ecore or UML metamodel.
> So my follow-up would have to be: why would you like to use generics
> in the Ecore model? That is, what's the purpose and power of this
> feature, and what can be achieved?
In addition to Ed's comment, you might use generics in Ecore wherever
you felt motivated to use templates in UML.

Regards

Ed Willink
Previous Topic:Re: problems deploying org.eclipse.rap.demo (EMF editor)
Next Topic:Using Extended MetaData feature kind "Element"
Goto Forum:
  


Current Time: Thu Mar 28 18:18:25 GMT 2024

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

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

Back to the top