Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [xtend] instanceof
[xtend] instanceof [message #516766] Wed, 24 February 2010 21:00 Go to next message
No real name is currently offline 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 #516771 is a reply to message #516766] Wed, 24 February 2010 20:06 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1755
Registered: July 2009
Senior Member
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


--
Have you heard about XtextCON?
Go to: http://www.xtextcon.org
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
No real name is currently offline 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 03:40 Go to previous messageGo to next message
MaximeLecourt  is currently offline 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 05:17]

Report message to a 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
Sven Efftinge is currently offline Sven Efftinge
Messages: 1755
Registered: July 2009
Senior Member
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


--
Have you heard about XtextCON?
Go to: http://www.xtextcon.org
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
MaximeLecourt  is currently offline 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...
Previous Topic:Help Eoposite to Xtext
Next Topic:Re: Using Jet with recursive data structures
Goto Forum:
  


Current Time: Wed Apr 16 18:50:00 EDT 2014

Powered by FUDForum. Page generated in 0.02440 seconds