|
Re: Generics in EMF [message #689954 is a reply to message #689855] |
Tue, 28 June 2011 16:19 |
Ed Merks 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 #690478 is a reply to message #690299] |
Wed, 29 June 2011 14:46 |
Ed Merks 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/
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02438 seconds