Model-to-Code Transformations for Specific Cloud Infrastructures


The migration phase of the ARTIST project consists of two steps. The first one, namely reverse engineering step, deals with the abstraction of the original application into platform-independent models (PIMs), which keep no information about any specific platform. The second step, forward engineering, has as final target the production of code targeted at a specific platform. In the process of obtaining this final code, the PIMs are first transformed into platform-specific models (PSMs), which contain information about the particular platform where the application is to be eventually deployed. After the PSMs have been obtained, the work presented in this deliverable can be applied, namely the generation of code from models.

This document describes the code generation approach implemented as model-to-text transformations developed in the context of the ARTIST project until M24. In particular, this document describes the design rationale behind the code generators. One of the main design rationales is to provide reusable code generators for the core of UML, which is considered to be the UML Class Diagram. The code generators are designed to be extensible for different cloud target platforms in order to counteract the recreation of standard code generation functionality that is needed for targeting general programming languages, i.e., in the context of ARTIST, Java and C#.

One may assume that available code generators are providing sufficient support for the UML class diagram modeling concepts as there is a plethora of different UML-based code generators available in open-source as well as in commercial tools. However, after evaluating several code generators, we explored that only some elements are properly treated by the available code generators and that substantive extensions of those are needed in order to cover a broader spectrum of the UML Class Diagram language. In this respect, we have in particular focussed on the constraints imposed by UML Class diagrams for their Object Diagrams, i.e., their instances, to be reflected as well in the generated code. Especially, the aspect that a UML Class Diagram also represents a constraint language for the object structure is mostly neglected by current code generators as they mostly consider the possibility to instantiate objects from classes and setting their values, but in a more or less unrestricted way.

This document therefore explains several approaches for implementing model-to-text transformations in order to realize code generators as well as important aspects such as how code generators may be extended or configured. Subsequently we explain two of our current code generators. While the first one is dedicated to Java, based on an open source code generator, and customized for one particular cloud platform, the second one is an extension of a code generator currently available in the Enterprise Architect tool considering C# code generation. Both generators come with dedicated contracts which act as pre-conditions to check the validity of the input models. Here not only the constraints of the UML metamodel are considered, but also the target constraints of the output languages such as naming rules and reserved keywords are checked before the code generation is actually started. By this additional step, many errors such as compile time errors in the generated code can be prevented.

As we have realized that developing code generators may sound simpler than it actually is, we report also on the validation of code generators by reasoning about completeness and correctness of the generators as well as the non-functional properties of the generated code such as readability and maintainability. For this validation concerns, we present a dedicated methodology which could be used also in future generator developments.

By contributing first versions of base code generators for Java and C#, by demonstrating how these code generators can be extended and configured for particular cloud platforms, and by showing how they can be validated, we pave the way to develop further cloud provider specific code generators in the last year of the ARTIST project which will be reported in the context of WP 10 in M30.