Saving modification of a Map in a function [message #1712240] |
Thu, 22 October 2015 06:51  |
Eclipse User |
|
|
|
In my transformation, I have to put a number to objects. The number has to increment for each object (order doesn't matter). But the increment depend on a category (I have to increment from 0 for each category).
So I figure out to make a Map(String, Integer) where String contains the category and Integer contains the current increment. The Map is init with value -1 for all the categories.
And then, I created a function like the following.
helper def : getNumber(id: String) : Integer =
thisModule.myMap
.including(id, thisModule.myMap.get(id) + 1)
.get(id);
but then, I realized that the function is returning a copy, not the object itself. Which means the Map never updates. Looking a bit in ATL documentation, I found out that I could use the function to solve that problem.
helper def : getNumber(id: String) : Integer =
thisModule.refSetValue('myMap',
thisModule.myMap
.including(id, thisModule.myMap.get(id) + 1)
)
.get(id);
Doing this, my ATL transformation file doesn't work anymore (it doesn't generate the XMI file). With the previous version, it does (even if the numbering is incorrect).
Any idea?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.29144 seconds