Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Saving modification of a Map in a function
Saving modification of a Map in a function [message #1712240] Thu, 22 October 2015 10:51 Go to next message
Jean Simard is currently offline Jean SimardFriend
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
including
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
refSetValue
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 Go to previous messageGo to next message
Jean Simard is currently offline Jean SimardFriend
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

Re: Saving modification of a Map in a function [message #1712504 is a reply to message #1712354] Mon, 26 October 2015 08:41 Go to previous message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 552
Registered: July 2009
Senior Member
Maybe you could try
let fake : OclAny = thisModule.refSetValue('myMap',thisModule.myMap.including(id, thisModule.myMap.get(id) + 1)) in
thisModule.myMap.get(id);
Previous Topic:Stereotype attribute using ATL
Next Topic:[ATL] transform generic EList type in generic EMF class
Goto Forum:
  


Current Time: Sun Nov 19 03:23:27 GMT 2017

Powered by FUDForum. Page generated in 0.02195 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software