How to access EList template type at runtime [message #417052] |
Mon, 25 February 2008 11:42 |
Eclipse User |
|
|
|
Originally posted by: john.obyrne.gmail.com
Hi,
I would like at runtime to be able to do
if (element instanceof EList<MyTemplate>)
// Do something
else if (element instanceof EList<MyOtherTemplate>)
// Do something else
....
I know it's not possible to know at runtime the template type (even using
reflection) in java. In the previous code generated engine we used, we had a
method on our Collection which was:
T getManagedType() {
return T.class;
}
which allowed us to know the Template type at runtime.
Is there a possibility in EMF to get the template type at runtime? (using
EMF self describing capability maybe)
Thanks,
John
|
|
|
|
Re: How to access EList template type at runtime [message #417063 is a reply to message #417055] |
Mon, 25 February 2008 17:25 |
Eclipse User |
|
|
|
Originally posted by: john.obyrne.gmail.com
Thanks, it works perfectly :)
I use the following code:
public static boolean isCollectionOf(EList<?> list, Class<?> type) {
if (list instanceof Setting) {
Setting setting = (Setting) list;
if
(type.isAssignableFrom(setting.getEStructuralFeature().getEG enericType().getEClassifier().getInstanceClass()))
return true;
}
return false;
}
"Ed Merks" <merks@ca.ibm.com> wrote in message
news:fpub8h$l56$1@build.eclipse.org...
> John,
>
> The lists returned by multi-valued references always implements
> EStructuralFeature.Setting which provides access to the EStructuralFeature
> managed by that list, which in turn provides access to the feature's
> eType, i.e., the EClassifier. For a generated model, that EClassifier's
> instance class would be what you're after.
>
>
> John O'Byrne wrote:
>> Hi,
>>
>> I would like at runtime to be able to do
>> if (element instanceof EList<MyTemplate>)
>> // Do something
>> else if (element instanceof EList<MyOtherTemplate>)
>> // Do something else
>> ....
>>
>> I know it's not possible to know at runtime the template type (even using
>> reflection) in java. In the previous code generated engine we used, we
>> had a method on our Collection which was:
>>
>> T getManagedType() {
>> return T.class;
>> }
>>
>> which allowed us to know the Template type at runtime.
>>
>> Is there a possibility in EMF to get the template type at runtime? (using
>> EMF self describing capability maybe)
>>
>> Thanks,
>> John
>>
>>
|
|
|
Powered by
FUDForum. Page generated in 0.01471 seconds