daanvdh/JavaForger

Generated code variable initialization

daanvdh opened this issue · 1 comments

When generating unit tests with JavaForger, two fields of the same type will have the same initialization value. However, we would like the initialization value to be unique.

With the input fields = {int x, int y} and template:

<#list fields as field>
${field.type} ${field.name} = ${field.init1}; 
</#list>

This will produce the following output:

int x = 1; 
int y = 1; 

The desired output would be:

int x = 1; 
int y = 3; 

To do this the VariableInitializer should be extended. It should keep track of variables that are already used for the current, probably by incrementing a counter per type. To prevent code duplication for numbers (int, long, ... ) we can as a first step just assign integer values only. We will still need the two initialization values per VariableDefinition, since we want to have the option to give the same field different values. Possibly the VariableInitializer needs to be split since it is growing fast.

fixed in feature/override