Tutorial | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Downloads

QVT Tutorial - 3

Before we continue, you might want to know a bit about creating these metamodels yourself. As I said before, I use Eclipse (Modeling Tools) to create them.
In Eclipse, create a new General Project, and name it "Tutorial". Next, create a New Ecore Diagram (in the Directory Tutorial), and name it MMA.ecore.
I like to see a grid in my modeling environment. Go to Properties, "Rulers & Grid", and set Grid Line Style to Solid, color to Black. Next, check the "Snap to Grid" and "Snap to Shapes" boxes and check "Show Grid".
Now you can place EClass boxes onto your Grid, and connect them by an EReference or Inheritance. To add an attribute to a Class, move your cursor to the Class (don't click it). A balloon with a rectangle and a gearwheel will appear, click the rectangle to add an attribute:

Ok, the metamodels are ready (either you created them yourself or downloaded them). Before we can start writing the Transformation, there should be an instance of metamodel MMA available (this means a Project with - for now - just one Automaton, the one depicted in the diagram in the first part of this tutorial). We will need this instance to test the Transformation.

Create a new General Project, called MMA. In this project, create an EMF Generator Model (MMA.genmodel), import Ecore Model (from the Tutorial Directory), click Next, Finish.
In Eclipse there now is a MMA.genmodel, right-click on it and choose "Generate All". Repeat these steps for the MMB metamodel.

Now, click File, Export, choose "Deployable plug-ins and fragments", select the 4 MMA options and the 4 MMB options. The Destination Directory should be "eclipse", NOT "eclipse/plugings" because the Export Wizard automatically does this.

Restart Eclipse. Now we have the option to create a MMA or MMB model when we press Ctrl + N. Choose MMA Model, save it as "Instance.mma" in the Tutorial directory. The "Model Object" (after you press Next) should be "Project". Click Finish.

Right click on Project, and add an Automaton as Child. Next, add four Locations to the Automaton: a Rectangle, Ellipse, Triangle, Rectangle. Assign the right names (see the diagram in the first part of this tutorial), do the same for the other attributes.
Now, add Edges and Updates where needed. Don't forget to assign the right Attributes: For an Edge, choose an Action (once again, like in the diagram) and a Target Location. Updates should have Variable Children. Assign a Name to each Variable, and a Type (doesn't matter what type).
That's it, finally right-click on Project and choose "Validate". When you get the message "Validation completed succesfully", your Instance.mma should look like this:

We can now start working on the transformation itself. Continue...