Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMT (Generative Modeling Technologies) » OAW - Type Casting with XTend
OAW - Type Casting with XTend [message #383890] Mon, 16 June 2008 12:25 Go to next message
Eclipse User
Originally posted by: any.swc.rwth-aachen.de

I have specified the following in my Extension:

cached int getConnectorCount(uml::ConnectorEnd e) :
uml::MultiplicityElement.isInstance(e.role) ?
e.getPartWithPortMultiplicity() * e.upper() *
((uml::MultiplicityElement)e.role).upper()
: e.getPartWithPortMultiplicity() * e.upper()
;

The cast of e.role into MultiplicityElemenet is acknowledged by the OAW
environement with the error "cannot cast from uml::ConnectableElement into
uml::MultiplicityElement". The dynamic type of e.role may however by a
MultiplicityElement. What am I doing wrong?
Re: OAW - Type Casting with XTend [message #383899 is a reply to message #383890] Tue, 24 June 2008 11:13 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

Hi Alexander,

you get this error because those types are not in a type hierarchy and
cannot be casted therefore.

The type hierarchy is as follows:

Element <- NamedElement <- TypedElement <- ConnectableElement
Element <- MultiplicityElement

You may consult the UML2 superstructure. Seems that the
ConnactableElement's role is not an MultiplicityElement.

~Karsten

Alexander Nyßen schrieb:
> I have specified the following in my Extension:
>
> cached int getConnectorCount(uml::ConnectorEnd e) :
> uml::MultiplicityElement.isInstance(e.role) ?
> e.getPartWithPortMultiplicity() * e.upper() *
> ((uml::MultiplicityElement)e.role).upper()
> : e.getPartWithPortMultiplicity() * e.upper()
> ;
>
> The cast of e.role into MultiplicityElemenet is acknowledged by the OAW
> environement with the error "cannot cast from uml::ConnectableElement
> into uml::MultiplicityElement". The dynamic type of e.role may however
> by a MultiplicityElement. What am I doing wrong?
>


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: OAW - Type Casting with XTend [message #383900 is a reply to message #383899] Tue, 24 June 2008 12:52 Go to previous messageGo to next message
Eclipse User
Originally posted by: any.swc.rwth-aachen.de

Yes of course they are not in the same hierarchy, that's why I indeed need
the cast!
Just assume e.role is a Property, which is a ConnectableElement as well as
MultiplicityElement.

Best Regards
Alexander Nyßen


"Karsten Thoms" <karsten.thoms@itemis.de> schrieb im Newsbeitrag
news:g3qkt1$njg$1@build.eclipse.org...
> Hi Alexander,
>
> you get this error because those types are not in a type hierarchy and
> cannot be casted therefore.
>
> The type hierarchy is as follows:
>
> Element <- NamedElement <- TypedElement <- ConnectableElement
> Element <- MultiplicityElement
>
> You may consult the UML2 superstructure. Seems that the
> ConnactableElement's role is not an MultiplicityElement.
>
> ~Karsten
>
> Alexander Nyßen schrieb:
>> I have specified the following in my Extension:
>>
>> cached int getConnectorCount(uml::ConnectorEnd e) :
>> uml::MultiplicityElement.isInstance(e.role) ?
>> e.getPartWithPortMultiplicity() * e.upper() *
>> ((uml::MultiplicityElement)e.role).upper()
>> : e.getPartWithPortMultiplicity() * e.upper()
>> ;
>>
>> The cast of e.role into MultiplicityElemenet is acknowledged by the OAW
>> environement with the error "cannot cast from uml::ConnectableElement
>> into uml::MultiplicityElement". The dynamic type of e.role may however by
>> a MultiplicityElement. What am I doing wrong?
>>
Re: OAW - Type Casting with XTend [message #383902 is a reply to message #383900] Wed, 25 June 2008 13:31 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

You could override your upper() function, assuming a default for non
MultiplicityElements, then upper() will also be recognized for
ConnectableElement and if it is at runtime a MultiplicityElement the
appropriate function will be called.

int upper (MultiplicityElement this) : upper;

int upper (Element this) : 1;


cached int getConnectorCount(uml::ConnectorEnd e) :
uml::MultiplicityElement.isInstance(e.role) ?
e.getPartWithPortMultiplicity() * e.upper() *
(e.role.upper()
: e.getPartWithPortMultiplicity() * e.upper()


Alexander Nyßen schrieb:
> Yes of course they are not in the same hierarchy, that's why I indeed
> need the cast!
> Just assume e.role is a Property, which is a ConnectableElement as well
> as MultiplicityElement.
>
> Best Regards
> Alexander Nyßen
>
>
> "Karsten Thoms" <karsten.thoms@itemis.de> schrieb im Newsbeitrag
> news:g3qkt1$njg$1@build.eclipse.org...
>> Hi Alexander,
>>
>> you get this error because those types are not in a type hierarchy and
>> cannot be casted therefore.
>>
>> The type hierarchy is as follows:
>>
>> Element <- NamedElement <- TypedElement <- ConnectableElement
>> Element <- MultiplicityElement
>>
>> You may consult the UML2 superstructure. Seems that the
>> ConnactableElement's role is not an MultiplicityElement.
>>
>> ~Karsten
>>
>> Alexander Nyßen schrieb:
>>> I have specified the following in my Extension:
>>>
>>> cached int getConnectorCount(uml::ConnectorEnd e) :
>>> uml::MultiplicityElement.isInstance(e.role) ?
>>> e.getPartWithPortMultiplicity() * e.upper() *
>>> ((uml::MultiplicityElement)e.role).upper()
>>> : e.getPartWithPortMultiplicity() * e.upper()
>>> ;
>>>
>>> The cast of e.role into MultiplicityElemenet is acknowledged by the
>>> OAW environement with the error "cannot cast from
>>> uml::ConnectableElement into uml::MultiplicityElement". The dynamic
>>> type of e.role may however by a MultiplicityElement. What am I doing
>>> wrong?
>>>
>


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: OAW - Type Casting with XTend [message #384381 is a reply to message #383900] Tue, 29 July 2008 06:16 Go to previous message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1762
Registered: July 2009
Senior Member
Alexander Nyßen schrieb:
> Yes of course they are not in the same hierarchy, that's why I indeed
> need the cast!
> Just assume e.role is a Property, which is a ConnectableElement as well
> as MultiplicityElement.

strange multiple inheritance ;-)
Then you should cast it down to (Property) or use the approach Karsten
mentioned.

Sven


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: OAW - Type Casting with XTend [message #618088 is a reply to message #383890] Tue, 24 June 2008 11:13 Go to previous message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

Hi Alexander,

you get this error because those types are not in a type hierarchy and
cannot be casted therefore.

The type hierarchy is as follows:

Element <- NamedElement <- TypedElement <- ConnectableElement
Element <- MultiplicityElement

You may consult the UML2 superstructure. Seems that the
ConnactableElement's role is not an MultiplicityElement.

~Karsten

Alexander Nyßen schrieb:
> I have specified the following in my Extension:
>
> cached int getConnectorCount(uml::ConnectorEnd e) :
> uml::MultiplicityElement.isInstance(e.role) ?
> e.getPartWithPortMultiplicity() * e.upper() *
> ((uml::MultiplicityElement)e.role).upper()
> : e.getPartWithPortMultiplicity() * e.upper()
> ;
>
> The cast of e.role into MultiplicityElemenet is acknowledged by the OAW
> environement with the error "cannot cast from uml::ConnectableElement
> into uml::MultiplicityElement". The dynamic type of e.role may however
> by a MultiplicityElement. What am I doing wrong?
>


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: OAW - Type Casting with XTend [message #618090 is a reply to message #383899] Tue, 24 June 2008 12:52 Go to previous message
Eclipse User
Originally posted by: any.swc.rwth-aachen.de

Yes of course they are not in the same hierarchy, that's why I indeed need
the cast!
Just assume e.role is a Property, which is a ConnectableElement as well as
MultiplicityElement.

Best Regards
Alexander Nyßen


"Karsten Thoms" <karsten.thoms@itemis.de> schrieb im Newsbeitrag
news:g3qkt1$njg$1@build.eclipse.org...
> Hi Alexander,
>
> you get this error because those types are not in a type hierarchy and
> cannot be casted therefore.
>
> The type hierarchy is as follows:
>
> Element <- NamedElement <- TypedElement <- ConnectableElement
> Element <- MultiplicityElement
>
> You may consult the UML2 superstructure. Seems that the
> ConnactableElement's role is not an MultiplicityElement.
>
> ~Karsten
>
> Alexander Nyßen schrieb:
>> I have specified the following in my Extension:
>>
>> cached int getConnectorCount(uml::ConnectorEnd e) :
>> uml::MultiplicityElement.isInstance(e.role) ?
>> e.getPartWithPortMultiplicity() * e.upper() *
>> ((uml::MultiplicityElement)e.role).upper()
>> : e.getPartWithPortMultiplicity() * e.upper()
>> ;
>>
>> The cast of e.role into MultiplicityElemenet is acknowledged by the OAW
>> environement with the error "cannot cast from uml::ConnectableElement
>> into uml::MultiplicityElement". The dynamic type of e.role may however by
>> a MultiplicityElement. What am I doing wrong?
>>
Re: OAW - Type Casting with XTend [message #618093 is a reply to message #383900] Wed, 25 June 2008 13:31 Go to previous message
Karsten Thoms is currently offline Karsten Thoms
Messages: 354
Registered: July 2009
Location: Dortmund
Senior Member

You could override your upper() function, assuming a default for non
MultiplicityElements, then upper() will also be recognized for
ConnectableElement and if it is at runtime a MultiplicityElement the
appropriate function will be called.

int upper (MultiplicityElement this) : upper;

int upper (Element this) : 1;


cached int getConnectorCount(uml::ConnectorEnd e) :
uml::MultiplicityElement.isInstance(e.role) ?
e.getPartWithPortMultiplicity() * e.upper() *
(e.role.upper()
: e.getPartWithPortMultiplicity() * e.upper()


Alexander Nyßen schrieb:
> Yes of course they are not in the same hierarchy, that's why I indeed
> need the cast!
> Just assume e.role is a Property, which is a ConnectableElement as well
> as MultiplicityElement.
>
> Best Regards
> Alexander Nyßen
>
>
> "Karsten Thoms" <karsten.thoms@itemis.de> schrieb im Newsbeitrag
> news:g3qkt1$njg$1@build.eclipse.org...
>> Hi Alexander,
>>
>> you get this error because those types are not in a type hierarchy and
>> cannot be casted therefore.
>>
>> The type hierarchy is as follows:
>>
>> Element <- NamedElement <- TypedElement <- ConnectableElement
>> Element <- MultiplicityElement
>>
>> You may consult the UML2 superstructure. Seems that the
>> ConnactableElement's role is not an MultiplicityElement.
>>
>> ~Karsten
>>
>> Alexander Nyßen schrieb:
>>> I have specified the following in my Extension:
>>>
>>> cached int getConnectorCount(uml::ConnectorEnd e) :
>>> uml::MultiplicityElement.isInstance(e.role) ?
>>> e.getPartWithPortMultiplicity() * e.upper() *
>>> ((uml::MultiplicityElement)e.role).upper()
>>> : e.getPartWithPortMultiplicity() * e.upper()
>>> ;
>>>
>>> The cast of e.role into MultiplicityElemenet is acknowledged by the
>>> OAW environement with the error "cannot cast from
>>> uml::ConnectableElement into uml::MultiplicityElement". The dynamic
>>> type of e.role may however by a MultiplicityElement. What am I doing
>>> wrong?
>>>
>


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: OAW - Type Casting with XTend [message #618621 is a reply to message #383900] Tue, 29 July 2008 06:16 Go to previous message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1762
Registered: July 2009
Senior Member
Alexander Nyßen schrieb:
> Yes of course they are not in the same hierarchy, that's why I indeed
> need the cast!
> Just assume e.role is a Property, which is a ConnectableElement as well
> as MultiplicityElement.

strange multiple inheritance ;-)
Then you should cast it down to (Property) or use the approach Karsten
mentioned.

Sven


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Previous Topic:OAW xpt and counters
Next Topic:[Epsilon] Problem with HUTN and sqlmodel
Goto Forum:
  


Current Time: Thu Sep 18 20:01:07 GMT 2014

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

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