Getting all Instances of an association in ATL [message #1417723] |
Fri, 05 September 2014 23:32 |
|
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 #1418228 is a reply to message #1418185] |
Sat, 06 September 2014 19:00 |
|
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!
[Updated on: Sat, 06 September 2014 19:24] Report message to a moderator
|
|
|
|
Re: Getting all Instances of an association in ATL [message #1419464 is a reply to message #1418842] |
Mon, 08 September 2014 16:59 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03436 seconds