How to make mutable sequence in Acceleo?

41 Views Asked by At

So i have a sequence of Visualization Attribute called vizAttrs. This is what I actually want to do:

[for (va: VisualizationAttribute | dataBinding2.eContents(VisualizationAttribute))]
[vizAttrs = vizAttrs->excluding(va) /]
[/for]

If I check the element of vizAttrs after the loop, it will still contain the va that I expect to be excluded. But if I tried something like:

[for (va: VisualizationAttribute | dataBinding2.eContents(VisualizationAttribute))]
[let newVizAttrs:Sequence(VisualizationAttribute) = vizAttrs->excluding(va) /]
[/for]

When I check it, the newVizAttrs does have the expected value, which excludes that va element. But newVizAttrs couldn't be used for the next iteration of that for loop. I assumed it's probably because somehow vizAttrs is immutable. Is there any way to make vizAttrs, or Sequence/Collection, mutable in Acceleo?

2

There are 2 best solutions below

0
alisha yumna On

I found that apparently all variables in Acceleo are finals. Source: https://stackoverflow.com/a/12003064/12466641

Seems like it is not possible to mutate vizAttrs in my case. I will search for a workaround instead.

0
Vincent Aranega On

If I understand well what you're trying to do, you want to remove all the VisualizationAttribute instances contained in dataBinding2 from vizAttr.

You don't need to mutate nothing here, you can just reject them from vizAttr.

vizAttrs->reject(e | dataBinding2.eContents(VisualizationAttribute)->includes(e))