Saving modification of a Map in a function [message #1712240] |
Thu, 22 October 2015 10:51 |
Jean Simard Messages: 2 Registered: October 2015 |
Junior Member |
|
|
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?
Jean Simard
R&D Engineer XWiki SAS
Contributor to XWiki
|
|
|
Re: Saving modification of a Map in a function [message #1712354 is a reply to message #1712240] |
Fri, 23 October 2015 09:18 |
Jean Simard Messages: 2 Registered: October 2015 |
Junior Member |
|
|
OK, not sure I completely understand the problem but it seems that the function `getNumber` with `refSetValue` in it cannot be called in the`to` part of a rule, only in the `do` part. The function `getNumber` without `refSetValue` has no problem to be in one or the other part of a rule. So maybe `refSetValue` cannot be used anywhere (but I didn't see this information in the documentation).
Jean Simard
R&D Engineer XWiki SAS
Contributor to XWiki
[Updated on: Fri, 23 October 2015 13:14] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03804 seconds