OAW - Type Casting with XTend [message #383890] |
Mon, 16 June 2008 08:25  |
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 #384381 is a reply to message #383900] |
Tue, 29 July 2008 02:16  |
Eclipse User |
|
|
|
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
|
|
|
Re: OAW - Type Casting with XTend [message #618088 is a reply to message #383890] |
Tue, 24 June 2008 07:13  |
Eclipse User |
|
|
|
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 #618090 is a reply to message #383899] |
Tue, 24 June 2008 08:52  |
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 09:31  |
Eclipse User |
|
|
|
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?
>>>
>
|
|
|
Re: OAW - Type Casting with XTend [message #618621 is a reply to message #383900] |
Tue, 29 July 2008 02:16  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.05850 seconds