0

I have a element with a child element name nextElement

a.nextElement is b
b.nextElement is c
c.nextElement is d

When I do a request a->closure(a.nextElement) I expect to get a set with b, c and d but I only get b. What I am not understanding or doing wrong?

Martin Paquin
  • 83
  • 1
  • 7

1 Answers1

0

Have you tried something like?:

a -> closure(child:Element | true)

true is an expression. You can specify there any condition you need.

I saw it here

Even though I'm not sure that closure is included in Acceleo API (I repeat, not sure). I tried to use closure function but the IDE didn't suggested it to me.

In my project, I made this generic query by my own:

[query public descendants(aElement : Node): 
    Set(Node) =  if (aElement.oclIsTypeOf(Element)) then
                        Set{aElement} -> union (aElement.oclAsType(Element).children 
                            -> collect (n : Node | descendants(n)) -> asSet() )  
                    else
                        Set{aElement}
                    endif 
    /]

I hope this would help !!!

Juan Aguilar Guisado
  • 1,687
  • 1
  • 12
  • 21
  • Actually, the Acceleo compiler/engine are able to deal with closure, but the IDE is not (not sure why). In the example provided by Martin, the way the deal with reccursive call could be `a->closure(child : Element | child.nextElement)` or, for short, `a->closure(nextElement)` . If the expression originally provided by Martin was not working, it is because of the variable binding (`a` is not free anymore). Var `a` is binded to an instance durig execution. Reusing it in the closure does not invalidate this binding so the expression `a->nextElement` always should resolve to the same result. – Vincent Aranega Apr 23 '15 at 06:49