Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Access to keys in EMap member of model element(Access to keys in EMap member of model element)
Access to keys in EMap member of model element [message #1780744] Fri, 26 January 2018 14:53 Go to next message
Bruce Trask is currently offline Bruce TraskFriend
Messages: 58
Registered: July 2009
Member
Hello,

I used the steps from
https://wiki.eclipse.org/EMF/FAQ#How_do_I_create_a_Map_in_EMF.3F
to create a map in one of my model elements. It ends up generating an EMap.

My question is how to access that and the keys and values of its elements via the OCL or from the .mtl file in Acceleo.

In the OCL Interpreter view I enter

aql:self.theSystem.services.nameToPackageName // nameToPackageName is the map

as the expression

and I get back

one->two
three->four

which is what the map contains (two key value pairs)

If I do aql:self.theSystem.services.nameToPackageName->asSequence()
I get the same result.

What I am trying to do is iterate through the map to get the individual keys and values.
->at() does not seem to do the trick with the Map.

I was hoping for something like ->get(key) but that does not appear to exist.

I could not find anything with regard to working with Maps in aql or OCL.

Regards,
Bruce


[Updated on: Fri, 26 January 2018 14:56]

Report message to a moderator

Re: Access to keys in EMap member of model element [message #1780757 is a reply to message #1780744] Fri, 26 January 2018 16:35 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6004
Registered: July 2009
Senior Member
Hi

(The new Pivot-based OCL adds a Map class to the OCL Standard Library; it has an at() operation. Unfortunately Acceleo has not migrated to exploit the new Pivot OCL.)

I have tried occasionally to exploit EMap without success. You may see my most recent attempt in https://bugs.eclipse.org/bugs/show_bug.cgi?id=443021

Since EMap is actually a linear list, you won't see the speedups for large Maps that you might expect, but for small maps the list can be faster...

If you really want a good Map I suggest you hand code the map in your *Impl.java with friendly accessor methods.

Regards

Ed Willink

Previous Topic:Mulitple input models to Acceleo
Next Topic:Traceability
Goto Forum:
  


Current Time: Sun Aug 19 21:03:13 GMT 2018

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

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

Back to the top