[ATL] need to do a calcul one Time [message #32979] |
Sat, 21 April 2007 14:14  |
Eclipse User |
|
|
|
Originally posted by: touzitou.enstimac.fr
Hi to all ATL man and women;
My problem i think it is easy but i can't resolve it (:)
i need to do some calcul(find some values) in the input model of my
transformation for one time. Because it's very heavy to do it (to call
the helper) in every matched rule.
i try to do this
use a helper :
helper def: cisPoolId: String=0;
and initialize it in a do{} section of my first matched rule.. but after
in the next rule my helper is always 0. so i understand that we apply do
sections of one matched rules once all the matched rules are applied. it
is that ?
Ok but how can i do ??
Thxs for help !!!
|
|
|
|
|
|
|
Re: [ATL] need to do a calcul one Time [message #34743 is a reply to message #33222] |
Fri, 27 April 2007 11:18  |
Eclipse User |
|
|
|
Hello,
I would also add that when you define an attribute helper, the result is
cached. This means that the computation is actually performed only once.
You may check this by adding a .debug('message') expression within your
helper (e.g., at the end, but not within an iterator). The message
should be printed only once, which shows that the body of the helper is
evaluated only once. This would be different with an operation attribute
(try adding () after the definition and usage of your helper).
I believe it is interesting to note this, because this means that you
may solve this task *without* using imperative code, only declarative,
which is the recommended way to use ATL :-).
However, obviously, if you *really* need imperative code to perform your
computation, then the solution provided by Marcos is more appropriate.
Regards,
Frédéric Jouault
jihed wrote:
> GREAT !!
> It is exactly what i need !!
> I vOte ATL !!
> Thxs Marcus !!
>
>
>
>
>
> Marcos Didonet Del Fabro a écrit :
>> Hi
>>
>> If you do it only once, you can do it using an entrypoint rule. An
>> entrypoint rule is executed before all the other rules. It is
>> typically used to initialize model elements.
>>
>> Syntax:
>>
>> entrypoint rule FirstRule {
>> to
>> ...
>> do {
>> ...
>> }
>> }
>>
>> Regards,
>>
>> Marcos.
>>
>> jihed wrote:
>>> Hello Marcos!
>>>
>>> Thxs for answer ! so the conclusion is that's not possible to do a
>>> calcul in a input model for one time (example : extraction of some
>>> values) and then to use the result of this calcul in matched rules.??
>>>
>>> We have to do a calcul every time needed in matched rules ??
>>> it's a problem because this calcul in input metamodel is heavy (2
>>> minutes) and do it for 50 times..is really not good..!!!!
>>>
>>> Jihed
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Marcos Didonet Del Fabro a écrit :
>>>> Hello,
>>>>
>>>> the matched rules are declarative, so it doesn't mean that the first
>>>> rule in the module will be executed first. Maybe that's the reason
>>>> why the helper's value is 0.
>>>>
>>>> I give below a simple example of attriuute helper that is used to
>>>> count the number of times a rule is executed:
>>>>
>>>>
>>>> helper def : countRules : Integer = 1;
>>>>
>>>> rule Example
>>>>
>>>> ....
>>>>
>>>> do {
>>>> thisModule.countRules <- thisModule.countRules + 1;
>>>> }
>>>>
>>>>
>>>> Regards,
>>>>
>>>> Marcos.
>>>>
>>>> jihed wrote:
>>>>> Hi to all ATL man and women;
>>>>>
>>>>> My problem i think it is easy but i can't resolve it (:)
>>>>> i need to do some calcul(find some values) in the input model of my
>>>>> transformation for one time. Because it's very heavy to do it (to
>>>>> call the helper) in every matched rule.
>>>>> i try to do this
>>>>> use a helper :
>>>>> helper def: cisPoolId: String=0;
>>>>> and initialize it in a do{} section of my first matched rule.. but
>>>>> after in the next rule my helper is always 0. so i understand that
>>>>> we apply do sections of one matched rules once all the matched
>>>>> rules are applied. it is that ?
>>>>> Ok but how can i do ??
>>>>> Thxs for help !!!
|
|
|
Powered by
FUDForum. Page generated in 0.17203 seconds