Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Does ATL support type casting?
[ATL] Does ATL support type casting? [message #71169] Wed, 09 January 2008 15:40 Go to next message
Mikai Yang is currently offline Mikai YangFriend
Messages: 149
Registered: July 2009
Senior Member
Hi,
I am wandering ATL support type casting or not. If so, how can we cast
a variable to another type, which is a sub-type of the original type. If
not, how can we handle the situation in which type casting is unavoided?
Thanks.
Best regards.
Michael.
Re: [ATL] Does ATL support type casting? [message #71228 is a reply to message #71169] Wed, 09 January 2008 16:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mikael.barbero.gmail.com

The OCL cast (oclAsType) operation is not supported by ATL but I do not
ever met a situation where type casting is unavoidable ;)
Post your situation there, we may help you!

Best regards,
Mikael

Michael wrote:
> Hi,
> I am wandering ATL support type casting or not. If so, how can we cast
> a variable to another type, which is a sub-type of the original type. If
> not, how can we handle the situation in which type casting is unavoided?
> Thanks.
> Best regards.
> Michael.
>
>



--
Mikaël Barbero - PhD Candidate
ATLAS Group (INRIA & LINA) - University of Nantes
2, rue de la Houssinière
44322 Nantes Cedex 3 - France
tel. +33 2 51 12 58 08 /\ cell.+33 6 07 63 19 00
email: Mikael.Barbero@{gmail.com, univ-nantes.fr}
http://www.sciences.univ-nantes.fr/lina/atl/
Re: [ATL] Does ATL support type casting? [message #71345 is a reply to message #71228] Wed, 09 January 2008 17:26 Go to previous messageGo to next message
Mikai Yang is currently offline Mikai YangFriend
Messages: 149
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.

------=_NextPart_000_00E6_01C852E4.B99303E0
Content-Type: text/plain;
charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,=20
For example, we have the following metamodel.=20
class Car {
color : Color=20
}=20
=20
abstract class Color{
}=20

class Red extends Color {
date: Java.util.Date // the purchase =
date. =20
person: String // The name of =
the person who painted this color.=20
}

class Blue extends Color{=20
date: Java.util.Date =20
}

class Green extends Color {
date: Java.util.Date
}
=20
From above metamodel, we know Car is associated with Color. =
Color has three sub-classes: Red, Blue, Green.=20

Now, we would like to use a contextual hepler of Car to get =
the painting record of one car.=20

We first define a contextual attribute of Color, like:=20

helper context Color def:colorRecord:String =3D =

if self.oclIsTypeOf(Red) then 'Red ' + =
'Painted by ' + self.person + ' in ' + self.date=20
else
if self.oclIsTypeOf(Blue) then 'Blue ' + =
'Painted by ' + self.person + ' in ' + self.date
else=20
if self.oclIsTypeOf(Green) then ''Green ' =
+ 'Painted by ' + self.person + ' in ' + self.date
endif =20

Then we get color history of a car, like=20
=20
helper context Car def: history(): String =3D =

let color: Color =3D self.color in=20
color.colorRecord
;=20

=20
In above, we hope to use 'self' to access attributes =
defined in the sub-classes of its type. This is illegal, unless we have =
cast the variable to a type of the corresponding subclass. This is why I =
raise the question about the type cast of ATL.=20
=20
I hope my example makes some sense. Thanks.=20

Best regards.=20
Michael.=20

=20

"Mika=EBl Barbero" <mikael.barbero@gmail.com> wrote in message =
news:fm2rvb$qg1$3@build.eclipse.org...
> The OCL cast (oclAsType) operation is not supported by ATL but I do =
not=20
> ever met a situation where type casting is unavoidable ;)
> Post your situation there, we may help you!
>=20
> Best regards,
> Mikael
>=20
> Michael wrote:
>> Hi,
>> I am wandering ATL support type casting or not. If so, how can =
we cast=20
>> a variable to another type, which is a sub-type of the original type. =
If=20
>> not, how can we handle the situation in which type casting is =
unavoided?
>> Thanks.
>> Best regards.
>> Michael.=20
>>=20
>>=20
>=20
>=20
>=20
> --=20
> Mika=EBl Barbero - PhD Candidate
> ATLAS Group (INRIA & LINA) - University of Nantes
> 2, rue de la Houssini=E8re
> 44322 Nantes Cedex 3 - France
> tel. +33 2 51 12 58 08 /\ cell.+33 6 07 63 19 00
> email: Mikael.Barbero@{gmail.com, univ-nantes.fr}
> http://www.sciences.univ-nantes.fr/lina/atl/
------=_NextPart_000_00E6_01C852E4.B99303E0
Content-Type: text/html;
charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.3243" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;&nbsp; For example, =
we have the=20
following metamodel. </FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;=20
class Car {</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;=20
color : Color </FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; }=20
</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;=20
</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;abstract&nbsp;&nbsp;class=20
Color{</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
} </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
class Red extends Color {</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;date:=20
Java.util.Date&nbsp;&nbsp;&nbsp;&nbsp; // the&nbsp;purchase date.=20
&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;person:=20
String&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& ;nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // =
The name=20
of the person who painted this color. </FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;=20
}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;=20
class Blue extends Color{&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;=20
date: Java.util.Date&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;=20
}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;=20
class Green extends Color {</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;date:=20
Java.util.Date</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;=20
}</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=20
</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;From above =
metamodel, we=20
know&nbsp;Car is associated with&nbsp;Color. Color has three =
sub-classes: Red,=20
Blue, Green. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Now, we =
would like=20
to&nbsp;use a contextual hepler of Car to get the&nbsp;painting record =
&nbsp;of=20
one car. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;We first =
define a=20
contextual attribute of Color, like: </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp; helper context Color def:colorRecord:String =3D=20
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;if=20
self.oclIsTypeOf(Red) then 'Red ' + 'Painted by '&nbsp;&nbsp;+<U>=20
self.person</U> + ' in ' + <U>self.date</U>=20
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;=20
else</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;=20
if self.oclIsTypeOf(Blue) then 'Blue ' + 'Painted by '&nbsp;&nbsp;+=20
<U>self.person</U> + ' in ' + <U>self.date</U></FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;=20
else&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;if=20
self.oclIsTypeOf(Green) then ''Green ' + 'Painted by '&nbsp;&nbsp;+=20
<U>self.person</U> + ' in ' + <U>self.date</U></FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;=20
endif&nbsp;&nbsp;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Then we=20
get&nbsp;color&nbsp;history of&nbsp;a car, like </DIV>
<DIV>&nbsp;</DIV>
<DIV> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n b=
sp;&nbsp;&nbsp;&nbsp;helper=20
context&nbsp;Car def:&nbsp;history():&nbsp;String =3D </DIV>
<DIV> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n b=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
let &nbsp;color: Color =3D self.color in </DIV>
<DIV> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n b=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb s=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;=20
color.colorRecord</DIV>
<DIV> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n b=
sp;&nbsp;&nbsp;&nbsp;=20
; </DIV>
<DIV>&nbsp;</DIV></FONT></DIV></FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; In=20
above, we hope to use 'self' &nbsp;to access attributes defined in the=20
sub-classes of its type. This is illegal, unless we have cast the =
variable to a=20
type of the corresponding subclass. This is why I raise the question =
about the=20
type cast of ATL. </FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;=20
I hope my example makes some sense. Thanks. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Best regards. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Michael. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>"Mika=EBl Barbero" &lt;</FONT><A=20
href=3D"mailto:mikael.barbero@gmail.com"><FONT face=3DArial=20
size=3D2>mikael.barbero@gmail.com</FONT></A><FONT face=3DArial =
size=3D2>&gt; wrote in=20
message </FONT><A href=3D"news:fm2rvb$qg1$3@build.eclipse.org"><FONT =
face=3DArial=20
size=3D2>news:fm2rvb$qg1$3@build.eclipse.org</FONT></A><FONT =
face=3DArial=20
size=3D2>...</FONT></DIV><FONT face=3DArial size=3D2>&gt; The OCL cast =
(oclAsType)=20
operation is not supported by ATL but I do not <BR>&gt; ever met a =
situation=20
where type casting is unavoidable ;)<BR>&gt; Post your situation there, =
we may=20
help you!<BR>&gt; <BR>&gt; Best regards,<BR>&gt; Mikael<BR>&gt; <BR>&gt; =
Michael=20
wrote:<BR>&gt;&gt; Hi,<BR> &gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;& ;nbsp; I am =
wandering=20
ATL support type casting or not. If so, how can we cast <BR>&gt;&gt; a =
variable=20
to another type, which is a sub-type of the original type. If =
<BR>&gt;&gt; not,=20
how can we handle the situation in which type casting is=20
unavoided?<BR> &gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;& ;nbsp; Thanks.<BR>&gt;&gt; =
Best=20
regards.<BR>&gt;&gt; Michael. <BR>&gt;&gt; <BR>&gt;&gt; <BR>&gt; =
<BR>&gt;=20
<BR>&gt; <BR>&gt; -- <BR>&gt; Mika=EBl Barbero - PhD Candidate<BR>&gt; =
ATLAS Group=20
(INRIA &amp; LINA) - University of Nantes<BR>&gt; 2, rue de la=20
Houssini=E8re<BR>&gt; 44322 Nantes Cedex 3 - France<BR>&gt; tel. +33 2 =
51 12 58 08=20
/\ cell.+33 6 07 63 19 00<BR>&gt; email: </FONT><A=20
href=3D"mailto:Mikael.Barbero@{gmail.com"><FONT face=3DArial=20
size=3D2>Mikael.Barbero@{gmail.com</FONT></A><FONT face=3DArial =
size=3D2>,=20
univ-nantes.fr}<BR>&gt; </FONT><A=20
href=3D"http://www.sciences.univ-nantes.fr/lina/atl/"><FONT face=3DArial =

size=3D2>http://www.sciences.univ-nantes.fr/lina/atl/</FONT></A></BODY></=
HTML>

------=_NextPart_000_00E6_01C852E4.B99303E0--
Re: [ATL] Does ATL support type casting? [message #71441 is a reply to message #71345] Thu, 10 January 2008 10:03 Go to previous message
Eclipse UserFriend
Originally posted by: mikael.barbero.gmail.com

Hi,

First of all, I don't see why you used let expression in the history
helper. Why don't you do simply:

helper context MM!Car def: history: String =
self.color.colorRecord;

Note that I removed "()" to make it an attribute helper, i.e. its
results is cached during the transformation execution.

Now, regarding your helper colorRecord, it should be illegal at
compile-time if ATL had a static typing systems similar to Java's. But
ATL is dynamically typed and then it will not throw any error at
compile-time for your helper but will fail at runtime (for the Blue
self.person and the Green self.person call).

Then, your helper should be rewritten like this (with a bit of
refactoring to make it cleaner ;) ):

helper context MM!Color def: colorRecord : String =
if self.oclIsTypeOf(MM!Red) then
'Red Painted by ' + self.person
else if self.oclIsTypeOf(MM!Blue) then
'Blue'
else if self.oclIsTypeOf(MM!Green) then
'Green'
endif endif endif + ' in ' + self.date;

And this is legal at runtime and will not fail at compile-time! It may
be harder to code and debug but it also offer more flexibility in your
ATL code.

Best regards,
Mikael


Michael wrote:
> Hi,
> For example, we have the following metamodel.
> class Car {
> color : Color
> }
>
> abstract class Color{
> }
>
> class Red extends Color {
> date: Java.util.Date // the purchase
> date.
> person: String // The name of
> the person who painted this color.
> }
>
> class Blue extends Color{
> date: Java.util.Date
> }
>
> class Green extends Color {
> date: Java.util.Date
> }
>
> From above metamodel, we know Car is associated with Color.
> Color has three sub-classes: Red, Blue, Green.
>
> Now, we would like to use a contextual hepler of Car to get
> the painting record of one car.
>
> We first define a contextual attribute of Color, like:
>
> helper context Color def:colorRecord:String =
> if self.oclIsTypeOf(Red) then 'Red ' +
> 'Painted by ' +_ self.person_ + ' in ' + _self.date_
> else
> if self.oclIsTypeOf(Blue) then 'Blue ' +
> 'Painted by ' + _self.person_ + ' in ' + _self.date_
> else
> if self.oclIsTypeOf(Green) then ''Green '
> + 'Painted by ' + _self.person_ + ' in ' + _self.date_
> endif
>
> Then we get color history of a car, like
>
> helper context Car def: history(): String =
> let color: Color = self.color in
> color.colorRecord
> ;
>
>
> In above, we hope to use 'self' to access attributes
> defined in the sub-classes of its type. This is illegal, unless we have
> cast the variable to a type of the corresponding subclass. This is why I
> raise the question about the type cast of ATL.
>
> I hope my example makes some sense. Thanks.
>
> Best regards.
> Michael.
>
>
>
> "Mikaël Barbero" <mikael.barbero@gmail.com
> <mailto:mikael.barbero@gmail.com>> wrote in message
> news:fm2rvb$qg1$3@build.eclipse.org...
> > The OCL cast (oclAsType) operation is not supported by ATL but I do not
> > ever met a situation where type casting is unavoidable ;)
> > Post your situation there, we may help you!
> >
> > Best regards,
> > Mikael
> >
> > Michael wrote:
> >> Hi,
> >> I am wandering ATL support type casting or not. If so, how can
> we cast
> >> a variable to another type, which is a sub-type of the original
> type. If
> >> not, how can we handle the situation in which type casting is unavoided?
> >> Thanks.
> >> Best regards.
> >> Michael.
> >>
> >>
> >
> >
> >
> > --
> > Mikaël Barbero - PhD Candidate
> > ATLAS Group (INRIA & LINA) - University of Nantes
> > 2, rue de la Houssinière
> > 44322 Nantes Cedex 3 - France
> > tel. +33 2 51 12 58 08 /\ cell.+33 6 07 63 19 00
> > email: Mikael.Barbero@{gmail.com <mailto:Mikael.Barbero@{gmail.com>,
> univ-nantes.fr}
> > http://www.sciences.univ-nantes.fr/lina/atl/



--
Mikaël Barbero - PhD Candidate
ATLAS Group (INRIA & LINA) - University of Nantes
2, rue de la Houssinière
44322 Nantes Cedex 3 - France
tel. +33 2 51 12 58 08 /\ cell.+33 6 07 63 19 00
email: Mikael.Barbero@{gmail.com, univ-nantes.fr}
http://www.sciences.univ-nantes.fr/lina/atl/
Previous Topic:[ATL] 'Continue execution' when launching programmatically
Next Topic:[ATL] resolveTemp
Goto Forum:
  


Current Time: Tue Apr 23 12:46:08 GMT 2024

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

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

Back to the top