Metamodel pattern matching example: ECore Queries


Have you ever tried to query a meta-model, i.e. a model consisting of EClasses, EAttributes, and EReferences, against a meta-model pattern? For an example, look here. In this case, we want to look for a certain sub-configuration in an ECore metamodel, where two EClasses (each having an EAttribute of type EString) are connected by a 0-* EReference.

Use-cases of this technique include meta-transformation, meta-model analysis, higher-order transformations where transformation rules are generated/parameterized by metamodel analysis etc.

We would like to sincerely thank Christian Schweda for the inspiration for this example.

Obtaining the example

Make sure you run the latest IncQuery tooling and runtime by downloading and installing from the nightly update site.

Check out the source project from Subversion:

Running the example

  1. Generate the "Sample UI" project (after installing a nightly version of IncQuery, right click on the .incquery model in this project, select EMF-IncQuery|Generate Sample UI).
  2. Run a runtime Eclipse (Run as | Eclipse Application).
  3. Import the project into your runtime workspace as well, as there is a useful, pre-prepared .ecore file in the models/sample directory: My.ecore
  4. Right click on this, select Sample EMF-IncQuery queries|Get all matches of the "sampleQuery" pattern.
  5. You should see the match of the pattern according to the specification found in

The VTCL code in the models/vtcl folder (ecorequery.vtcl) contains comments to explain how the patterns work in detail. Some further technical notes:

  • in this example, we introduced the @SampleUI(scope="ResourceSet") or scope="Resource" annotation to allow the matching of patterns across multiple resources in a resourceset.
  • This works even in conjuction with "alien" resources outside of the resourceset, in case cross-references are made using nsURIs - this is a common case where e.g. datatypes from ECore are referenced inside typical EMF metamodels).