Domanda

I'm trying to count how many times a condition is true inside a FOR loop. I declared an additional variable for the template (FOUND : Integer), and I'm trying to increment it every time the [IF] condition is "true", but the variable increments only the first time, then it gets back to its original value. Basically, if FOUND = 1 at the beginning, at every loop I get 2 in output.

This is the code I'm trying to use:

[template public genPartnerLinkJavaFile(aProcess : Process, varNameList : Sequence{String} .... etc)
 {FOUND : Integer = 1;}]
    [file ('PL'+aPartnerLink.name.toUpperFirst()+'.java', false, 'UTF-8')]
    public class ['PL'+aPartnerLink.name.toUpperFirst()/] {

[for (aVariable  : Variable | aProcess.eAllContents(Variable))]  
    [if (varNameList->includes(aVariable.name.toString() ) )]
    [FOUND+1/]
    [i/]
    [/if]
[/for]  

Do you know how could I achieve this or something similar? Thanks

È stato utile?

Soluzione

In Acceleo, all variables are final. You can use a collection to store all used values and then compute its size or you could use a Java service if you really want to use a value. I would recommend using a query to compute all the useful elements since the result of the evaluation of a query is stored in a cache, the impact on the performances will be minimal.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top