Every ReMoDeL project is created as a new Java project in your favourite Java IDE. Every project must include the ReMoDeL kernel on its build path. The expected folders under the project root folder should look like this:
(.met)
files;(.mod)
files;(.tra)
files;We assume from here on that you have installed the example project RM_Trees following the instructions on the Download Page.
To view any of this project's metamodel, model or transformation file in your IDE's text editor, simply open the file as a text file. Examples include:
meta/InTree.met
, a metamodel of an in-tree;model/graph1.mod
, a model instance of a graph;rule/InTreeToGraph.tra
, a transformation.At various points, the ReMoDeL tools will create new files in your project. These may not initially be visible in your IDE, because it uses its own metadata to work out what to display. To get around this, you should learn how to Refresh your project, in your IDE. For example:
In Eclipse, right click on the project RM_Trees to bring up a menu. Select the Refresh option about halfway down. You may also use the F5 function key to refresh a selected project.
After this, you should be able to see the previously invisible file(s). Another useful trick is to Clean your project periodically, which forces all generated Java sources to be recompiled, if the compiled files have got out of step in your IDE.
In the src/home package you should find:
home.Validate.java
, a main program for checking the syntax of
your ReMoDeL files;home.Compile.java
, a main program for compiling your ReMoDeL
files to Java.In Eclipse, select Run > Run Configurations
and choose a name for this configuration. On the Main tab fill out the
project name RM_Trees, and the main class, e.g. home.Validate
.
On the Arguments tab fill the Program arguments box with the
relative pathname to a ReMoDeL file, e.g. meta/Graph.met
.
Click Apply to save, and Close to close.
In the meta folder you should find some metamodels to check:
meta/Graph.met
, a metamodel for a graph;meta/InTree.met
, a metamodel for an in-tree;meta/OutTree.met
, a metamodel for an out-tree.Run the Validate
program to check any of these. Specify the
desired pathname as a command-line argument, e.g. meta/Graph.met
.
If you already have a configuration for this, you can usually find it as one of
the drop-down options of your Run button. Run this.
Any syntax errors are reported on standard output. Otherwise, the metamodel
is read into memory, and as proof of this, is rewritten out to file called
meta/out.met
(refresh to see this). This is a temporary file,
which you can view and then delete. You should also see a success message
on standard output.
Run the Compile
program to compile a metamodel. This will
generate a new Java package under the src folder. To do this, set
up a new run configuration with the main program: home.Compile
,
and specify the desired pathname, e.g. meta/Graph.met
. Run this.
If no errors are found, you should see a success message on standard output,
and a Java package meta.graph
will have been added in your src
folder (refresh to see this).
Open the src folder to see the new Java
package meta.graph
sitting alongside the home
package.
You can open this package, to see how the metamodel has been converted into a set
of Java classes.
ReMoDeL Metamodel of an OutTree
Models are text serialisations of memory models, which are constructed from the Java classes you just compiled. To read a model, you must always have compiled its metamodel first! Otherwise, you will see the no metamodel class error message.
In the model folder you should find some models to check:
model/intree1.mod
, a model of an in-tree;model/outtree1.mod
, a model of an out-tree;model/graph.mod
, a model of a graph.Run the Validate
program to check the model syntax. Create
a new run configuration for this, supplying a path to the model file, e.g.
model/graph1.mod
. Run this.
Any syntax errors are reported on standard output. Otherwise, the model
is read into memory, and as proof of this, is rewritten out to file called
model/out.mod
(refresh to see this). This is a temporary file,
which you can view and then delete. You should also see a success message
on standard output.
Note that models are data, they cannot be compiled as code. But they are read, created, and written by model transformations.
In the rule folder you should find six transformations, whose names aptly describe what kind of transformation they each perform:
rule/GraphToInTree.tra
;rule/GraphToOutTree.tra
;rule/InTreeToGraph.tra
;rule/InTreeToOutTree.tra
;rule/OutTreeToGraph.tra
;rule/OutTreeToInTree.tra
.They can transform any kind of tree-like model into another, and back again!
You may open and view these files to figure out how they work. You can validate
any of these by running the Validate
program, specifying the desired
path, e.g. rule/InTreeToGraph.tra
. Run this.
Any syntax errors are reported on standard output. Otherwise, the transformation
is read into memory, and as proof of this, is rewritten out to file called
rule/out.tra
(refresh to see this). This is a temporary file, to be
deleted after reading.
Run the Compile
program to compile a transformation. This will
generate a new Java package under the src folder. To do this, set up a
new run configuration with the main program: home.Compile
, and
specify the desired pathname, e.g. rule/InTreeToGraph.tra
.
If no errors are found, you should see a success message on standard output,
and a Java package rule.trees
will have been added in your src
folder (refresh to see this). You can open the package, to see that a Java class
rule.trees.InTreeToGraph.java
has been created.
Furthermore, Java packages will have been added for each of the metamodels used
in this transformation. So, you should also see the Java packages:
meta.graph
and meta.intree
. Compiling a transformation
always recompiles any dependent metamodels, in case these were modified.
The generated Java class rule.trees.InTreeToGraph.java
can be run
like any Java main program. It expects a command-line argument giving the relative
path to the input source model. To execute this transformation, create a new run
configuration with the main program: rule.trees.InTreeToGraph
and
specifying the path: model/intree1.mod
as the input. Run this.
If no errors are found, you should see a success message on standard output,
and a temporary output model file model/out.mod
will have been
added to the model folder. You can open this file, and it should have
exactly the same structure as the file model/graph1.mod
, which proves
that you have just transformed an in-tree to a graph.
Transformation classes can also be used as just one step in a chain of model
transformations. In this case, their apply()
method is invoked
from a Java program that manages the transformation chain. To do this, you will
need to understand the Java representation of models and transformations.
Look Inside to
continue learning.