Question on Java/Acceleo/M2DOC? What does "closure" mean?

Hello,
I have developed an interest for this particular line of code:

m:for actor | self.containedSystemAnalysis.ownedSystemComponentPkg->closure(cPkg | cPkg.ownedSystemComponentPkgs).ownedSystemComponents->select(sComp | sComp.actor)

I tried to look up for the this “closure” part of this call, I cannot find it on AQL documentation ( Acceleo (eclipse.org)), nor in Java ( Java Closure - Javatpoint)?

How does this work? What does it do exaclty?


Another question is about the “select” feature.
In this FOR loop we have a variable actor which is equal to : ??? I can’t seem to put my finger on the value of actor on this line of code, is it :
self.containedSystemAnalysis.ownedSystemComponentPkg->at(n) ?
self.containedSystemAnalysis.ownedSystemComponentPkg.ownedSystemComponentPkgs->at(n)?
self.containedSystemAnalysis.ownedSystemComponentPkg.ownedSystemComponentPkgs.ownedSystemComponents->at(n)
If it’s equal to any of the above, how does it come i could not replace its value in the following part?
“select(sComp | sComp.actor)” who could become "select(sComp | sComp.insertOneofTheAbove)?)

Sorry if this is too obvious for the veteran in Java, maybe I am missing some basics that I hadn’t the chance to look at.
Thanks

The documentation seems outdated. You can find the documentation and the definition of the closure service here. This service will apply recursively the passed lambda expression and collect all results in an OrderedSet. For instance you could implement eAllContents() like this:

eObject->closure(e | e.eContents())

The expression in the for loop will navigate recursively the ownedSystemComponentPkgs and collect all SystemComponentPkg. With this OrderedSet of SystemComponentPkg, it then collect all ownedSystemComponents resulting in an OrderedSet of SystemComponent. And the select at the end will keep only SystemComponent that are actors. The lambda expression used in a select call needs to return a Boolean. There is an other service collect() that can collect result of a lambda. This is the same behavior as the “.” operator:

someObject.someExpression

is equivalent to

someObject->collect(o | o.someExpression)

Not that in the second expression the result will always be a Collection.

The value of the the variable actor will take the value of an element of the for expression on each loop until it has iterated over all elements of the Collection (for instance actor1 then actor2 … actorN).

1 Like