[xtend] instanceof [message #516766] |
Thu, 25 February 2010 02:00 |
No real name Messages: 62 Registered: July 2009 |
Member |
|
|
Hi,
suppose I have a meta model where there are classes
B and C that extend a class A and another model with
a class D.
B has an attribute of type b and C has an attribute of type c.
Also, D has an attribute of type d.
I want to write an extension like this:
create D this AToD(A aa):
// If A is a B, set D.d to B.b,
// if A is a C, set D.d to C.c
;
At first I thought I could just write several extensions
with the same name for every class:
create D this AToD(B bb) and create D this AToD(C cc)
However, I get this exception:
org.eclipse.core.commands.common.NotDefinedException: Cannot get the
parent identifier from an undefined context.
org.eclipse.ui.edit.text.actionSet.presentation
Then I thought I could write an Extension like this:
create D this AToD(A aa):
// If A is a B, return BToD
// if A is a C, return CToD
;
and also two extensions like this:
create D this BToD(B bb):
this.setd(bb.b)
;
create D this CToD(C cc):
this.setd(cc.c)
;
Is there something like an 'instanceof' operator in xtend
so I can use the latter approach? Or maybe the first is the
right one and i'm just doing something wrong?
Regards,
Matthias
|
|
|
|
Re: [xtend] instanceof [message #517066 is a reply to message #516771] |
Fri, 26 February 2010 01:11 |
No real name Messages: 62 Registered: July 2009 |
Member |
|
|
Hi Sven,
thank you for your reply. You are right, the exception seems to have
nothing to do with the extension. It's because it doesn't occur anymore.
If I find a way to reproduce it, I will file a bugzilla.
Regards,
Matthias
Sven Efftinge wrote:
> Matthias Schmeling schrieb:
>> I want to write an extension like this:
>>
>> create D this AToD(A aa):
>> // If A is a B, set D.d to B.b,
>> // if A is a C, set D.d to C.c
>> ;
>>
>> At first I thought I could just write several extensions
>> with the same name for every class:
>>
>> create D this AToD(B bb) and create D this AToD(C cc)
>
> Yes, that should work.
>
>> However, I get this exception:
>> org.eclipse.core.commands.common.NotDefinedException: Cannot get the
>> parent identifier from an undefined context.
>> org.eclipse.ui.edit.text.actionSet.presentation
>
> It shouldn't have something to do with the extension.
> Could you please file a bugzilla containing the stack trace and the
> example?
>
>>
>> Is there something like an 'instanceof' operator in xtend
>> so I can use the latter approach?
>
> Yes, it's: TypeName.isInstance(object)
>
> Sven
>
|
|
|
Re: [xtend] instanceof [message #517088 is a reply to message #516766] |
Fri, 26 February 2010 08:40 |
MaximeLecourt Messages: 108 Registered: February 2010 Location: France |
Senior Member |
|
|
Is there another function to check if an attribute is of a certain type ?
I want to redefine types (creating an age type, which is an Integer), and I want to check for every non-basic type that I create for what basic type they come from (and print that type).
superType creates a Set of all superTypes, but I can't find how to verify what type is in it.
thanks.
One day I shall master M2T, but that day has yet to come...
[Updated on: Fri, 26 February 2010 10:17] Report message to a moderator
|
|
|
|
Re: [xtend] instanceof [message #518135 is a reply to message #516766] |
Wed, 03 March 2010 08:44 |
MaximeLecourt Messages: 108 Registered: February 2010 Location: France |
Senior Member |
|
|
No, I had troubles with the basics on metamodeling, but its solved now (I think).
But still, thanks for answering, that answer helps me for something else.
Regards
maxime
One day I shall master M2T, but that day has yet to come...
|
|
|
Powered by
FUDForum. Page generated in 0.03766 seconds