Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [xtend] instanceof
[xtend] instanceof [message #516766] Wed, 24 February 2010 21:00 Go to next message
Eclipse UserFriend
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 #516771 is a reply to message #516766] Wed, 24 February 2010 20:06 Go to previous messageGo to next message
Eclipse UserFriend
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

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [xtend] instanceof [message #517066 is a reply to message #516771] Thu, 25 February 2010 20:11 Go to previous messageGo to next message
Eclipse UserFriend
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 03:40 Go to previous messageGo to next message
Eclipse UserFriend
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.

[Updated on: Fri, 26 February 2010 05:17] by Moderator

Re: [xtend] instanceof [message #518106 is a reply to message #517088] Wed, 03 March 2010 00:33 Go to previous messageGo to next message
Eclipse UserFriend
Hi Maxime,

MaximeLecourt schrieb:
> Is there another function to check if an attribute is of a certain type ?

Do you mean xpand2::Type?

You can write something like:

my::Type.allProperties.select(e|e.returnType.isAssignableFro m(OtherType))

Sven

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [xtend] instanceof [message #518135 is a reply to message #516766] Wed, 03 March 2010 03:44 Go to previous message
Eclipse UserFriend
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
Previous Topic:Help Eoposite to Xtext
Next Topic:Re: Using Jet with recursive data structures
Goto Forum:
  


Current Time: Wed May 14 18:02:23 EDT 2025

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

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

Back to the top