Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Three questions about 'lazy rules'
[ATL] Three questions about 'lazy rules' [message #52830] Tue, 17 July 2007 20:50 Go to next message
Eclipse UserFriend
Originally posted by: diego.alonso.upct.es

Hello all,

First of all, I want to thank you for this wonderful tool. I use lazy rules
and I have the following questions about them:

1) I have noticed that lazy rules do not perform such a good job with
inheritance relationship as matched rules do. It is easy to use a matched
rule in this case, but you (at least me) cannot define two lazy rules with
the same name and different 'from' parts that inherit from the same
abstract rule (I have made the parent abstract to avoid processing twice
the same input model element). For instance, let say that ClassA and ClassB
both inherit from the same abstract class Parent, and ClassC has a
reference called 'classes' which type is Parent. The following rules do not
work. Only the one that is written last in the .atl file is invoked:

thisModule.Class(classes); -- 'classes' can be any, ClassA or ClassB

lazy rule Class {
from f : inMM!ClassA
to t : outMM!ElemA,
t1 : outMM!ElemC
}

lazy rule Class {
from f : inMM!ClassB
to t : outMM!ElemB,
t1 : outMM!ElemD
}

My solution is to rename the rules and use oclIsTypeOf() to invoke the
correct one. But this is not an elegant solution, specially when it works
smoothly for matched rules.

2) What makes the elements generated by unique lazy rule "unique" in the
target model? I was trying to create unique elements by using the same
element from the input model and an Integer (for imitating an enumeration).
For example:

unique lazy rule test {
from f : inMM!ClassA,
n : Integer
to t : outMM!ElemA (...)
}

I have defined a couple of attributes:
helper def : value1 : Integer = 1;
helper def : value2 : Integer = 2;

and I invoke the lazy rule from another lazy/matched rule like this:
thisModule.test(element, thisModule.value1)
thisModule.test(element, thisModule.value2)

but only one "unique" element (the first one that invokes the unique rule)
is really created. I have remake the rule "test" so now I have two
different unique rules that do pretty much the same, but it would be nice
to have the transformation code in one and only one place.
Anyway, as there is no information about unique rules in the manual, it
would be nice if you could ask this question. Even more, would a unique
lazy rule work with many 'from' elements??

3) I need to use resolveTemp to target a non-default model element of a lazy
rule. I have read in another e-mail that it is possible to do that, but the
problem is that I am using inheritance in the 'from' part of the rule, and
I think ATL is not able to find the correct rule because. This is the error
message I get:

message: ERROR: could not find operation getNamedTargetFromSource
on Void having supertypes: [OclAny]

As you may have guessed, I "discovered" this while playing with example (1):
thisModule.resolveTemp (classes, 't1');

Well, I think it is more that enough with these three questions. Thank you
all in advance for your attention and patience.

Diego.
Re: [ATL] Three questions about 'lazy rules' [message #52978 is a reply to message #52830] Wed, 18 July 2007 13:30 Go to previous message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hello,

> First of all, I want to thank you for this wonderful tool.

Thanks ;-).


> I use lazy rules
> and I have the following questions about them:
>
> 1) I have noticed that lazy rules do not perform such a good job with
> inheritance relationship as matched rules do. It is easy to use a matched
> rule in this case, but you (at least me) cannot define two lazy rules
with
> the same name and different 'from' parts that inherit from the same
> abstract rule (I have made the parent abstract to avoid processing twice
> the same input model element). For instance, let say that ClassA and
ClassB
> both inherit from the same abstract class Parent, and ClassC has a
> reference called 'classes' which type is Parent. The following rules
do not
> work. Only the one that is written last in the .atl file is invoked:
>
> thisModule.Class(classes); -- 'classes' can be any, ClassA or
ClassB
>
> lazy rule Class {
> from f : inMM!ClassA
> to t : outMM!ElemA,
> t1 : outMM!ElemC
> }
>
> lazy rule Class {
> from f : inMM!ClassB
> to t : outMM!ElemB,
> t1 : outMM!ElemD
> }
>
> My solution is to rename the rules and use oclIsTypeOf() to invoke the
> correct one. But this is not an elegant solution, specially when it works
> smoothly for matched rules.

First, you cannot have two rules with the same name.

We have plans to add checks for this kind of condition and report
appropriate error messages. However, you have to make sure to avoid this
for the time being.


Second, lazy rule inheritance is being tested right now, but is not
available yet.

When it is available, it will definitely not work by having several
rules with the same name, but will rather use the same mechanism as for
standard rules: using the "abstract" and "extends" keywords.


> 2) What makes the elements generated by unique lazy rule "unique" in the
> target model? I was trying to create unique elements by using the same
> element from the input model and an Integer (for imitating an
enumeration).
> For example:
>
> unique lazy rule test {
> from f : inMM!ClassA,
> n : Integer
> to t : outMM!ElemA (...)
> }
>
> I have defined a couple of attributes:
> helper def : value1 : Integer = 1;
> helper def : value2 : Integer = 2;
>
> and I invoke the lazy rule from another lazy/matched rule like this:
> thisModule.test(element, thisModule.value1)
> thisModule.test(element, thisModule.value2)
>
> but only one "unique" element (the first one that invokes the unique
rule)
> is really created. I have remake the rule "test" so now I have two
> different unique rules that do pretty much the same, but it would be nice
> to have the transformation code in one and only one place.
> Anyway, as there is no information about unique rules in the manual, it
> would be nice if you could ask this question. Even more, would a unique
> lazy rule work with many 'from' elements??

When a unique lazy rule is executed, it always returns the same target
element for a given source element. The target element is retrieved by
navigating the internal traceability links, in a way similar to standard
rules.

Non-unique lazy rule do not navigate the traceability links, and create
new target elements at each execution.


> 3) I need to use resolveTemp to target a non-default model element of
a lazy
> rule. I have read in another e-mail that it is possible to do that,
but the
> problem is that I am using inheritance in the 'from' part of the
rule, and
> I think ATL is not able to find the correct rule because. This is the
error
> message I get:
>
> message: ERROR: could not find operation
getNamedTargetFromSource
> on Void having supertypes: [OclAny]
>
> As you may have guessed, I "discovered" this while playing with
example (1):
> thisModule.resolveTemp (classes, 't1');
>
> Well, I think it is more that enough with these three questions.
Thank you
> all in advance for your attention and patience.

You cannot use resolveTemp with lazy rules yet.

However, you can separate the elements creation in different unique lazy
rules and retrieve them by directly calling the appropriate rule.


Regards,

Frédéric Jouault
Previous Topic:[ATL] Problem while launching ATL programmatically
Next Topic:[ATL]Bug report : crash when compilation error
Goto Forum:
  


Current Time: Thu Apr 25 13:36:17 GMT 2024

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

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

Back to the top