Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "VIATRA/Query/UserDocumentation/AdvancedPatterns"
Line 1: | Line 1: | ||
= Working with EMaps in EMF-IncQuery = | = Working with EMaps in EMF-IncQuery = | ||
− | The eclipse.org EMF wiki gives a proper FAQ about the various modeling related issues, including the usage of EMap-s in your metamodel. With EMF-IncQuery you can even write your own queries to extract the key-value pairs from your instance model. <br> | + | The eclipse.org EMF wiki gives a proper FAQ about the various modeling related issues, including the usage of EMap-s in your metamodel. With EMF-IncQuery you can even write your own queries to extract the key-value pairs from your instance model. <br> |
== EMaps in your metamodel == | == EMaps in your metamodel == | ||
Line 18: | Line 18: | ||
#Set the upper-bound of your EReference to be -1 (unbounded).<br> | #Set the upper-bound of your EReference to be -1 (unbounded).<br> | ||
− | == EMaps in your instance model<br> == | + | == EMaps in your instance model<br> == |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | Here is an example query to extract the key-value pairs from an EMap<br> | ||
+ | pattern emapPattern(K : EString, V : EString) {<br> EMapTestElement(M); <br> EMapTestElement.map(M, Map); <br> EStringToEStringMap.key(Map, K);<br> EStringToEStringMap.value(Map, V);<br>}<br> | ||
Parts of this overview are based on the http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_i_create_a_Map_in_EMF.3F page. <br> | Parts of this overview are based on the http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_i_create_a_Map_in_EMF.3F page. <br> |
Revision as of 11:21, 5 April 2013
Working with EMaps in EMF-IncQuery
The eclipse.org EMF wiki gives a proper FAQ about the various modeling related issues, including the usage of EMap-s in your metamodel. With EMF-IncQuery you can even write your own queries to extract the key-value pairs from your instance model.
EMaps in your metamodel
- Creating the actual EMap type Create an EClass with the name [Type1]To[Type2]Map where [Type1] represents the key's type and the [Type2] represents the value's type.
- Set the Instance Type Name property of the newly created EClass to java.util.Map$Entry.
- Create an EAttribute or EReference named "key" and set the EDataType or EClass for it.
- Create an EAttribute or EReference called "value" and set the EDataType or EClass for it.
For example for an <EString, EString> EMap you would have an EClass named EStringToEStringMap if you follow the mentioned scheme.
To actually use this newly created type follow these steps:
- Create an EReference with its EClass set to be the map-entry class you created above.
- Set the Containment property of your EReference to be true.
- Set the upper-bound of your EReference to be -1 (unbounded).
EMaps in your instance model
Here is an example query to extract the key-value pairs from an EMap
pattern emapPattern(K : EString, V : EString) {
EMapTestElement(M);
EMapTestElement.map(M, Map);
EStringToEStringMap.key(Map, K);
EStringToEStringMap.value(Map, V);
}
Parts of this overview are based on the http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_i_create_a_Map_in_EMF.3F page.