Solving the TTC 2011 Reengineering Case with GReTL
📝 Original Info
- Title: Solving the TTC 2011 Reengineering Case with GReTL
- ArXiv ID: 1111.4747
- Date: 2011-10-01
- Authors: Gunter Saake, Markus Kahl
📝 Abstract
This paper discusses the GReTL reference solution of the TTC 2011 Reengineering case. Given a Java syntax graph, a simple state machine model has to be extracted. The submitted solution covers both the core task and the two extension tasks.💡 Deep Analysis

📄 Full Content
In contrast to most other transformation languages, GReTL transformations usually construct the target metamodel (schema) on their own, thereby specifying one graph conforming to this new schema as target graph of the transformation. For this purpose, GReTL provides a slim set of four transformation operations, which are derived from the metametamodel of the TGraph technological space (the GraphUML metaschema). There is an operation CreateVertexClass, which creates a new node type (Ver-texClass) in the target schema and a set of vertices of this new type in the target graph. Likewise, there is an operation CreateEdgeClass, which creates a new edge type (EdgeClass) in the target schema and a set of edges of this new type in the target graph. Since schemas allow for multiple inheritance between vertex as well as edge classes, there is an operation AddSubClass to create specialization relationships in the target schema. Finally, there is an operation CreateAttribute, which creates a new attribute for a vertex or edge class and which assigns values to the elements for which that new attribute is defined. The vertices and edges that have to be created in the target graph as well as the function assigning values are specified in terms of queries on the transformation’s source graph.
In this section, all tasks are discussed in sequence, and the GReTL operations and GReQL queries are explained when they come along. The solution can be run on the SHARE image [4].
The core task is responsible for creating States and Transitions without setting the attributes of the latter. Because the JaMoPP metamodel [3] splits its types into various packages, we import the packages from which elements are used, so that we can refer to these types without having to qualify them. The first task is the creation of State vertices. As explained in the task description, there is an abstract Java class named State, and all concrete subclasses can be considered states. At first, we bind abstract State class to a variable abstractStateClass, so that we can easily refer to it in the transformation.
wi th c . name = " S t a t e " r e p o r t S e t c end ) ;
The from-with-reportSet expression calculates the set of classes which are named “State”. The function theElement() extracts the single element of a collection consisting of only one element and throws an exception if the collection’s size is not one. This expresses the assumption that there is exactly one state class. Finally, this class is assigned to the variable abstractStateClass.
The first transformation operation invoked is CreateVertexClass. It creates a new vertex class State in the target schema. The query following the arrow symbol is evaluated on the source graph and has to result in a set. For each member of this set (archetype), a new vertex (image) of the just created type is instantiated in the target graph. The mappings from archetypes to target graph images are automatically saved in a function corresponding to the target metamodel vertex class (img State ).
C r e a t e V e r t e x C l a s s S t a t e 6 <== from c : { C l a s s } & (<>–{ e x t e n d s } <>–{ c l a s s i f i e r R e f e r e n c e s } –>{ t a r g e t })+ 7 a b s t r a c t S t a t e C l a s s The query specifies a set of Class vertices. The variable c iterates over Class vertices, for which a path to the vertex abstractStateClass exists. The structure of this path is specified using a regular path expression [1]. First, a containment edge with role name extends at the far end has to be traversed, followed by another containment edge with role name classifierReferences, followed by a forward edge with role name target. This is exactly how subclasses relate to their superclass. The + specifies a one-ormany iteration. Thus, c is bound not only to direct subclasses of abstractStateClass, but also to indirect ones. The with part ensures that c is not abstract, i.e., it must not reference an Abstract vertex using an edge with containment semantics and far end role name annotationsAndModifiers. For any non-abstract class that extends the abstract state class either directly or indirectly, a new target graph State vertex is created. The mappings from classes to states are stored in a function img State, which can be used in following operation calls for navigating between archetypes and images.
The next operation creates the name attribute of type String for the State vertex class, and it sets the attribute values for the vertices created by the last operation call.
C r e a t e A t t r i b u t e S t a t e . name : S t r i n g 11 <== from c : k e y S e t ( i m g S t a t e ) reportMap c -> c . name end ;
The query of the
📸 Image Gallery
