Uml2Mtl: generate the generator

OMG/MTL is the language of choice for writing model-to-text transformations. But why couldn’t we write the transformation in UML? This article is about a transformation of UML into Acceleo MTL that can generate itself!

The transformation transforms a Class in a module, operations into templates and preconditions into guards. Basically we define following operations/templates:

The uml2mtl package with one class representing an Acceleo module.

The uml2mtl package with one class representing an Acceleo module.

In Topcased, it is pretty easy to attach behaviour to an operation. For example, the main operation is define as such:

The body written in MTL of the generateMtlFromUml operation.

And 25 lines of Acceleo/MTL later, you got something working (download the source code Uml2Mtl project (355)). It is not yet robust but you get the idea. Moreover this example uses few corner case of OMG/MTL like guards (otherwise a file would be generated for each Behavior) and string quotation to escape special characters (‘[' and ']‘ mainly).

One may ask what could be the use of such a beast? Wait for the next article that will talk about the UML testing profile…

Discussion Area - Leave a Comment