Skip to main content



      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 06:51 Go to next message
Eclipse UserFriend
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?
Re: Saving modification of a Map in a function [message #1712354 is a reply to message #1712240] Fri, 23 October 2015 05:18 Go to previous messageGo to next message
Eclipse UserFriend
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).

[Updated on: Fri, 23 October 2015 09:14] by Moderator

Re: Saving modification of a Map in a function [message #1712504 is a reply to message #1712354] Mon, 26 October 2015 04:41 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 17:05:05 EDT 2025

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

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

Back to the top