Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Calling a lazy-rule(Once from a called-rule and once from a matched-rule for the same source-element)
Calling a lazy-rule [message #1623828] Thu, 19 February 2015 10:58 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hello,

I am trying to reuse some lazy-rules instead of implementing output-patterns twice.
My scenario sounds a little bit tricky:

1. I have a matched-rule (Attr2Field) for attributes of classes. In this matched rule, I call a lazy-rule (Attr2Getter) to generate some getters and to add it to the new created class, which owns the new created field

2. The same lazy-rule (Attr2Getter) is now called a second time, for the same source-elment but now from a called-rule. In this called rule I use the return-type of the lazy-rule (Attr2Getter) to generate the getter a second time.

Here some code for a better understanding:
rule Attr2Field{
  from source:IN!Attr
  to target:OUT!Field( )

  do{ 
    thisModule.Attr2Getter(source); --create getter for the also created "owning-class" of this field
   }
}

initGetterInInterface(source:IN!Attr, containingTargetClass: OUT!OtherClass){
to ...
do { 
     -- this source-element is used twice, once in a matched rule and once in a called-rule
     containingTargetClass.body <-containingTargetClass.body -> including(thisModule.Attr2Getter(source));
    }
}

lazy rule Attr2Getter{
	from
		from source:Attr
	using {
		containingSourceClass: IN!Class = source.refImmediateComposite();
		containingTargetClass: OUT!OtherClass =thisModule.resolveTemp(containingSourceClass, 'target');
	}
to getter:OUT!Method(
    containerClass <- containingTargetClass
)
}


Is this use of lazy-rules kind of a hack? Should I better create the needed elements in the called rule itself?

I initially thought, that the created getter will be added twice to the (also created) owning class, but this is not the case.

Any ideas welcome!

~Alex
Re: Calling a lazy-rule [message #1624149 is a reply to message #1623828] Thu, 19 February 2015 15:49 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 351
Registered: September 2012
Location: Belgium
Senior Member

No, this is not a hack. Lazy rules can be called multiple times, and return new elements every time. If you want "functional" behaviour, whereby the same output is returned every time you provide the same input, you can use unique lazy rules.

Also, the return value of a lazy rule is the return value of just that call, not of all the calls to the rule. Therefore, the owning class contains only one copy of the lazy rule output.


Cheers,
Dennis
Re: Calling a lazy-rule [message #1624347 is a reply to message #1624149] Thu, 19 February 2015 18:37 Go to previous message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Good to know!

Thanks a lot for your explanation.

Regards,
Alex
Previous Topic:[ATL] Transformation ends without output
Next Topic:ATL Run Configuration
Goto Forum:
  


Current Time: Fri Nov 24 22:28:10 GMT 2017

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

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