Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » eCore generics: runtime values?
icon5.gif  eCore generics: runtime values? [message #524070] Tue, 30 March 2010 14:24 Go to next message
Greg Mising name is currently offline Greg Mising nameFriend
Messages: 47
Registered: July 2009
Member
I've been experimenting with generics in the eCore model - defining eTypeParameters on eClassifiers in order to specialize references and attributes. I think this has incredible potential.

I know that Java currently discards their generic values for their classes at compile time so there is no way to know the value of the object's generic at run-time (except through the recursive api). Does EMF have a special way that it works around this for EClasses and their EObject instances? I've noticed that the generated package code initializes the EClassifiers, eReferences and eAttributes with their defined type parameters and generic types, however having looked at the EObject api I don't see any way to access any run-time values for those properties. Am I missing something or is this just wishful thinking?

Thanks,
Greg
Re: eCore generics: runtime values? [message #524075 is a reply to message #524070] Tue, 30 March 2010 15:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Greg,

Comments below.


Greg wrote:
> I've been experimenting with generics in the eCore model - defining
> eTypeParameters on eClassifiers in order to specialize references and
> attributes. I think this has incredible potential.
>
> I know that Java currently discards their generic values for their
> classes at compile time so there is no way to know the value of the
> object's generic at run-time (except through the recursive api). Does
> EMF have a special way that it works around this for EClasses and
> their EObject instances?
No, it's designed to work the same way as Java.
> I've noticed that the generated package code initializes the
> EClassifiers, eReferences and eAttributes with their defined type
> parameters and generic types,
The same is true for Java, i.e., all the declared generic information is
available, but a java.lang.Object only has a getClass() method and that
doesn't help determine any type arguments that might be passed to that
Class.
> however having looked at the EObject api I don't see any way to access
> any run-time values for those properties.
There's just an eClass() method and that only tells you the EClass, not
the type arguments.
> Am I missing something or is this just wishful thinking?
No, wishful thinking unfortunately.
>
> Thanks,
> Greg


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: eCore generics: runtime values? [message #524081 is a reply to message #524070] Tue, 30 March 2010 15:28 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Hi,
your question made me thinking. I am very curious, what exactly is your
use case for that?
Cheers
Jonas

Greg wrote:
> I've been experimenting with generics in the eCore model - defining
> eTypeParameters on eClassifiers in order to specialize references and
> attributes. I think this has incredible potential.
>
> I know that Java currently discards their generic values for their
> classes at compile time so there is no way to know the value of the
> object's generic at run-time (except through the recursive api). Does
> EMF have a special way that it works around this for EClasses and their
> EObject instances? I've noticed that the generated package code
> initializes the EClassifiers, eReferences and eAttributes with their
> defined type parameters and generic types, however having looked at the
> EObject api I don't see any way to access any run-time values for those
> properties. Am I missing something or is this just wishful thinking?
>
> Thanks,
> Greg
Re: eCore generics: runtime values? [message #524093 is a reply to message #524081] Tue, 30 March 2010 16:33 Go to previous message
Greg Mising name is currently offline Greg Mising nameFriend
Messages: 47
Registered: July 2009
Member
It's regarding code generation. Without knowing the generic type you can't create a type-safe object (e.g. EList). Well technically it's still type safe but at the super type not the generic type. This means, for example, that I can add any object that is a subclass of the super type to the EList even though the generic type of the object is some other subclass.

I just added a very long-winded comment and a test case to this bug if you're interested:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=289859

Cheers,
Greg
Previous Topic:Can I override/specialize an EFeature in a subclass?
Next Topic:EMF Validation: Dependency between constraints
Goto Forum:
  


Current Time: Thu Apr 25 16:32:09 GMT 2024

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

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

Back to the top