Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "VIATRA/Query/UserDocumentation/Examples/ecorequery"

(incomplete)
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
'''This example has not been updated to the latest versions of VIATRA Query!'''
 +
 +
While the source code is still available and the main concepts are similar to the current version, the example is outdated and refers to EMF-IncQuery.
 +
 
== Metamodel pattern matching example: Ecore Queries ==
 
== Metamodel pattern matching example: Ecore Queries ==
  
Line 4: Line 8:
  
 
Use-cases of this technique include meta-transformation, meta-model analysis, higher-order transformations where transformation rules are generated/parameterized by metamodel analysis etc.
 
Use-cases of this technique include meta-transformation, meta-model analysis, higher-order transformations where transformation rules are generated/parameterized by metamodel analysis etc.
 +
 +
 +
====Overview====
 +
 +
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 [http://wwwmatthes.in.tum.de/wikis/sebis/christian-m-schweda 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 GitHub:
 +
 +
* https://github.com/ujhelyiz/EMF-IncQuery-Examples/tree/master/ecorequery
 +
 +
====Running the example====
 +
 +
# Import the hu.bme.mit.ecorequery project into your workspace.
 +
# There is a file in src/hu.bme.mit.incquery.ecorequeries.example directory: queries.eiq, right click on this, select EMF-IncQuery queries | Register patterns in Query Explorer.
 +
# There is a useful, pre-prepared .ecore file in the models/sample directory: My.ecore. Open it, after that click on Load model in Query Explorer View (if you could not see this view then go to Window->Show View->Other->EMF-IncQuery->Query Explorer) .
 +
# You should see the match of the pattern according to the specification found in hu.bme.mit.ecorequery/spec/example.pdf in Query Explorer view.
 +
 +
 +
====Sample pattern====
 +
 +
The project contains a pattern named SampleQuery. This pattern looks for matches like the picture at the bottom in Ecore  Models.
 +
 +
 +
<source lang="java">
 +
import "http://www.eclipse.org/emf/2002/Ecore"
 +
 +
pattern SampleQuery(XElement, YElement, Relates, Label1, Label2) = {
 +
EClass(XElement);
 +
EClass.eStructuralFeatures(XElement,Relates);
 +
EReference(Relates);
 +
EClass(YElement);
 +
ETypedElement.eType(Relates,YElement);
 +
 +
find EReferenceWithStarMultiplicity(Relates);
 +
 +
find EClassWithEStringAttribute(XElement, Label1);
 +
find EClassWithEStringAttribute(YElement, Label2);
 +
 +
neg find IsInECore(XElement);
 +
neg find IsInECore(YElement);
 +
}
 +
</source>
 +
 +
 +
In the first section the pattern filters out two EClasses ('''XElement,YElement''') and the '''XElement''' contains a reference to '''YElement'''.
 +
 +
The '''find EReferenceWithStarMultiplicity(Relates)'''; helper pattern filters out references only with star multiplicity.
 +
 +
The '''find EClassWithEStringAttribute(XElement, Label1)'''; and the '''find EClassWithEStringAttribute(YElement, Label2)'''; helper pattern filters out EClasses which contains EString.
 +
 +
The '''neg find IsInECore(XElement)'''; and the '''neg find IsInECore(YElement)'''; excludes matching to elements located in Ecore.ecore.

Latest revision as of 10:08, 8 April 2016

This example has not been updated to the latest versions of VIATRA Query!

While the source code is still available and the main concepts are similar to the current version, the example is outdated and refers to EMF-IncQuery.

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.


Overview

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 GitHub:

Running the example

  1. Import the hu.bme.mit.ecorequery project into your workspace.
  2. There is a file in src/hu.bme.mit.incquery.ecorequeries.example directory: queries.eiq, right click on this, select EMF-IncQuery queries | Register patterns in Query Explorer.
  3. There is a useful, pre-prepared .ecore file in the models/sample directory: My.ecore. Open it, after that click on Load model in Query Explorer View (if you could not see this view then go to Window->Show View->Other->EMF-IncQuery->Query Explorer) .
  4. You should see the match of the pattern according to the specification found in hu.bme.mit.ecorequery/spec/example.pdf in Query Explorer view.


Sample pattern

The project contains a pattern named SampleQuery. This pattern looks for matches like the picture at the bottom in Ecore Models.


import "http://www.eclipse.org/emf/2002/Ecore"
 
pattern SampleQuery(XElement, YElement, Relates, Label1, Label2) = {
	EClass(XElement);
	EClass.eStructuralFeatures(XElement,Relates);
	EReference(Relates);
	EClass(YElement);
	ETypedElement.eType(Relates,YElement);
 
	find EReferenceWithStarMultiplicity(Relates);
 
	find EClassWithEStringAttribute(XElement, Label1);
	find EClassWithEStringAttribute(YElement, Label2);
 
	neg find IsInECore(XElement);
	neg find IsInECore(YElement);
}


In the first section the pattern filters out two EClasses (XElement,YElement) and the XElement contains a reference to YElement.

The find EReferenceWithStarMultiplicity(Relates); helper pattern filters out references only with star multiplicity.

The find EClassWithEStringAttribute(XElement, Label1); and the find EClassWithEStringAttribute(YElement, Label2); helper pattern filters out EClasses which contains EString.

The neg find IsInECore(XElement); and the neg find IsInECore(YElement); excludes matching to elements located in Ecore.ecore.

Back to the top