[ATL]Guard condition at target element in matched rule [message #800642] |
Fri, 17 February 2012 10:01  |
Eclipse User |
|
|
|
Hi all,
I am facing a problem when realizing a transformation to a model without the certainty of the existence of its elements. For example, in this following rule, I am not sure about the existence of the elements elem1, elem2, ... in the MMB!B model, so I need to perform some kinds of guard conditions to make sure the rule is not going to raise an error about the existence of elem1, elem2, ...
rule Transform
from i : MMA!A
to o : MMB!B
(
elem <- i.elem,
elem1 <- i.elem1 (guard condition 1),
elem2 <- i.elem2 (guard condition 2),
...
)
Untill now, after reading the ATL manual and the discussions on this forum, I found one solution. The Transformation rule can be separated in to many rules corresponding to each guard condition as follow:
rule Transform0
from i : MMA!A (not guard condition 1 and not guard condition 2)
to o : MMB!B
(
elem <- i.elem
)
rule Transform1 extends Transform0
from i : MMA!A (guard condition 1 and not guard condition 2)
to o : MMB!B
(
elem1 <- i.elem1
)
rule Transform2 extends Transform0
from i : MMA!A (not guard condition 1 and guard condition 2)
to o : MMB!B
(
elem2 <- i.elem2
)
rule Transform3 extends Transform0
from i : MMA!A (guard condition 1 and guard condition 2)
to o : MMB!B
(
elem1 <- i.elem1,
elem2 <- i.elem2
)
With 2 "uncertain" attributes in the target model, we have got already 4 additional rules, how about 3, 4 or more attributes?
I thought also about putting the guard conditions in the imperative section of ATL rules but it turned out that we cannot mix matched rules in imperative code. For instance, writing
rule Transform
from i : MMA!A
to o : MMB!B
(
elem <- i.elem
)
do
[
if (guard condition 1)
o.elem1 <- i.elem1;
...
}
will not give the attended results because the rule to transform from one elem to another elem is a matched one!
I wonder if anyone has got the same problem? Your help will be well appreciated!
[Updated on: Fri, 17 February 2012 10:05] by Moderator Report message to a moderator
|
|
|
Re: [ATL]Guard condition at target element in matched rule [message #800984 is a reply to message #800642] |
Fri, 17 February 2012 19:31   |
Eclipse User |
|
|
|
On 17/02/12 11:01, Capi Tali wrote:
> Hi all,
> I am facing a problem when realizing a transformation to a model without the
> certainty of the existence of its elements. For example, in this following
> rule, I am not sure about the existence of the elements elem1, elem2, ... in
> the MMB!B model, so I perform some guard condition to make sure the rule is
> not going to raise an error about the existence of elem1, elem2, ...
> rule Transform
> from i : MMA!A
> to o : MMB!B
> (
> elem <- i.elem,
> elem1 <- i.elem1 (guard condition 1),
> elem2 <- i.elem2 (guard condition 2),
> ..
> )
Is this what you need:
rule Transform {
from i : MMA!A
to o : MMB!B (
elem <- i.elem,
elem1 <- if (guard condition 1) then i.elem1 else OclUndefined endif,
elem2 <- if (guard condition 2) then i.elem2 else OclUndefined endif,
..
elemColl <- if (guard condition 2) then i.elemColl else Sequence{} endif,
)
}
Dennis
|
|
|
|
Powered by
FUDForum. Page generated in 0.03089 seconds