Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Getting all Instances of an association in ATL
Getting all Instances of an association in ATL [message #1417723] Fri, 05 September 2014 23:32 Go to next message
Hamid Qartal is currently offline Hamid QartalFriend
Messages: 33
Registered: December 2013
Member
Hi,

Supose I have a variable refName which its value is the name of an association from A to B, and a variable aInst of type A. How can I access the SET(B) that refName association referes to from aInst?

Having it formulated in ATL helper template, What would be the body of the following helper in ATL if A is a type and refName is the name of one of A's EReferences?

helper def : refCollection(aInst : A, refName:String) : Set(OclAny) =
	....


Thanks

[Updated on: Sat, 06 September 2014 00:38]

Report message to a moderator

Re: Getting all Instances of an association in ATL [message #1418185 is a reply to message #1417723] Sat, 06 September 2014 17:34 Go to previous messageGo to next message
Hamid Qartal is currently offline Hamid QartalFriend
Messages: 33
Registered: December 2013
Member
Any hint on this guys!?

or any place that I can look for this?! any comment is very appreciated!
Re: Getting all Instances of an association in ATL [message #1418228 is a reply to message #1418185] Sat, 06 September 2014 19:00 Go to previous messageGo to next message
Hamid Qartal is currently offline Hamid QartalFriend
Messages: 33
Registered: December 2013
Member
Ok guy, I find the solution for this by hacking inside the ATL code. Looking inside the EMFModelAdapter suggested the way I can do this:

eGet is a method name in EObject that returns the value for the given EStructuredFeature!:

eGet
     java.lang.Object eGet(EStructuralFeature feature)



Also getEReferences() method in EClass returns the list of EReferences of a Type! Hence the following helper would return Ereference of a Type by providing EReference name:

helper def : getRef(a : OclAny, arrow : String) : OclAny =
	a->getEReferences()->select(r|r.name=arrow)->asSequence()->first();


Now using the above helper, we can write a helper which gets a feature name and an instance, and returns the values of that feature for that instance:

helper def : refCollection(aInst : OclAny, refName:String) : Set(OclAny) =
	aInst.eGet(thisModule.getRef(aInst.oclType(), refName));


great! Razz

[Updated on: Sat, 06 September 2014 19:24]

Report message to a moderator

Re: Getting all Instances of an association in ATL [message #1418842 is a reply to message #1418228] Sun, 07 September 2014 18:51 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 606
Registered: September 2012
Location: Belgium
Senior Member

Eh, doesn't refGetValue() do what you want?

See https://wiki.eclipse.org/ATL/User_Guide_-_The_ATL_Language#OclAny_operations


Cheers,
Dennis
Re: Getting all Instances of an association in ATL [message #1419464 is a reply to message #1418842] Mon, 08 September 2014 16:59 Go to previous message
Hamid Qartal is currently offline Hamid QartalFriend
Messages: 33
Registered: December 2013
Member
Hi Dennis,

Oh! I missed that ATL is providing such an operation! my bad!
refGetValue() is exactly the operation I needed. It is returning the values of a feature, provided its name!

I think refGetValue() is specific to ATL and not supported in OCL. right?! So, I hope at least my workaround become useful if somebody wants the same operation in EMF!

Thanks
Hamid
Previous Topic:convert atl-0.2 model to atl files
Next Topic:atl transformation
Goto Forum:
  


Current Time: Mon Sep 23 04:41:35 GMT 2024

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

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

Back to the top