[ATL] Lazy rules and multiple instantiations [message #560036] |
Mon, 20 September 2010 16:58  |
Eclipse User |
|
|
|
Hello everybody,
can me anybody explain why lazy rules with multiple instantiations do not working?
I try someting like this (I tryed to do such things in some parts of my project, but the result is the same):
rule r1 {
from
a : A!Model
to
m: B!Pool ( packagedElement<-A!Class.allInstances()->collect(a | thisModule.r2(a))
)
}
unique lazy rule r2 {
from
a : A!Class
to
s: B!Data (),
t: B!Data (),
flow: B!SequenceFlow (
fSource<-s,
fTarget<-t
)
}
I get as Output such structure:
<model>
<data/>
</model>
<data/>
<sequenceFlow/>
How can I get such structure?:
<model>
<data/>
<data/>
<sequenceFlow/>
</model>
Is it possible at all? If yes, how? If not, why?
Thanks everybody for your answer.
Best regards,
Katja
|
|
|
Re: [ATL] Lazy rules and multiple instantiations [message #560077 is a reply to message #560036] |
Tue, 21 September 2010 03:05   |
Eclipse User |
|
|
|
Your lazy rule only returns the first element.
So when you call that rule (->collect(a | thisModule.r2(a))), this returns the Data aliased s and only that.
Still, the data t and the flow are created but not affected so are placed at the root of the resulting model.
To solve this you can either use a called rule to specify what it should return :
rule r2(a : A!Class){
to
s: B!Data (),
t: B!Data (),
flow: B!SequenceFlow (
fSource<-s,
fTarget<-t
)
do{
--here you specify what the rule must return :
Sequence{s,t,flow};
}
} You'll lose the "unique" behavior though.
You can also use three unique lazy rules instead of just one :
rule r1 {
from
a : A!Model
to
m: B!Pool (
packagedElement<-A!Class.allInstances()
->collect(a |
let dataS : B!Data = thisModule.dataS(a) in
let dataT : B!Data = thisModule.dataT(a) in
let flow : B!SequenceFlow = thisModule.flow(a,dataS,dataT) in
Sequence{dataS,dataT,flow}
)
)
}
unique lazy rule dataS {
from
a : A!Class
to
s: B!Data ()
}
unique lazy rule dataT {
from
a : A!Class
to
t: B!Data ()
}
unique lazy rule flow {
from
a : A!Class, s : B!Data, t : B!Data
to
flow: B!SequenceFlow (
fSource<-s,
fTarget<-t
)
}
[Updated on: Tue, 21 September 2010 03:07] by Moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.05914 seconds