DSL Design Language Implementation Strategies g g p g Generic Language Technology 2IS15 g g gy Model Transformations • Stand-alone • Embedding Marcel van Amstel • Translation / Software Engineering and Technology 9-1-2012 PAGE 2 Model Transformations Model Transformations • Semi-Thue systems y A model transformation is a mapping from a set of source models to a set of target models defined as a set of transformation rules.
Model Transformations Model transformations • Model transformation / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 6 Model Transformations Model transformations • Model transformation formalisms Implementation approaches p pp • ATL • ASF+SDF • Direct model manipulation • Xtend • Stratego/XT • Xtext • VIATRA • Intermediate representation • Xpand • Tefkat • QVT Relations • ETL (Epsilon) ( p ) • Model transformation language • QVT Operations • GrGen • QVT Core • … • Platform: Eclipse and EMF / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 8
Model Transformations Model transformations • The Atlas Transformation Language (ATL) is a hybrid language • ATL characteristics: ATL characteristics: (a mix of declarative and imperative constructions) designed to express model transformations • Hybrid language (declarative and imperative constructs) • A model transformation in ATL is expressed as a set of • Transformation is a set of transformation rules and transformation rules • Hybrid style of programming: helpers Declarative transformation based on simple mappings • Imperative for complex mappings • • OCL for source model navigation • OCL is used to expression constraints on rules • Limited escape mechanism to use Java • Guards (constraints) on the entry point for a rule ( ) y p • Documentation: http://www.eclipse.org/gmt/atl/doc • In-place transformation simulated using refining mode • Documentation: www eclipse org/m2m/atl/doc/ • Documentation: www.eclipse.org/m2m/atl/doc/ / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 10 Model transformations Model transformations • An ATL transformation program is composed of • An example of an ATL specification g rules that define how • The goal is to present a use case of a model to model • source model elements are matched and navigated transformation written in ATL • to create and initialize the elements of the target models • to create and initialize the elements of the target models • The ATL programs for model to model • This use case is named: “Books to Publications” transformation are called modules • Initially we have a text describing a list of books t a y e a e a te t desc b g a st o boo s • We want to transform this into another text describing a list of publications / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 11 / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 12
Model transformations Model transformations • ATL: Book2Publication example • ATL: Book2Publication example MMM Ecore conformsTo conformsTo conformsTo conformsTo conformsTo conformsTo MM t ATL MM MM a MM b MM MM Book MM MM Publication MM conformsTo conformsTo conformsTo conformsTo conformsTo conformsTo M t Book2Publication M a M b Book Publication Transformation Transformation / Faculteit Wiskunde en Informatica / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 13 9-1-2012 PAGE 14 Model transformations Model transformations • Meta-model of Book: • Meta-model of Publication: • Example of Book: E l f B k / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 15 / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 16
Model transformations Model transformations • First we create an ATL • First we have to create/ project obtain meta-models • Getting started • Select in Eclipse • Next we create an ATL file S l t i E li N t t ATL fil − File/New/ATL Project • Getting started • Select then the Finish • Select in Eclipse Select in Eclipse button b tt − File/New/ATL File • Select then the Next button / Faculteit Wiskunde en Informatica / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 17 9-1-2012 PAGE 18 Model transformations Model transformations • Next we have to set the • A detailed description of the transformation can be Input/Output parameters found at: of ATL transformation: http://wiki.eclipse.org/ATL/Tutorials_- • Select then the Finish Select then the Finish _Create_a_simple_ATL_transformation Create a simple ATL transformation button • This will generate automatically the header section section / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 19 / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 20
Model transformations Model transformations • ATL transformation code • Header: • A header section that defines some attributes that are • The header section names the transformation module and names the variables corresponding to the source and target relative to the transformation module models ("IN" and "OUT") together with their meta-models (“Book" and “Publication") acting as types. • An optional import section that enables to import some existing ATL libraries module Book2Publication; module Book2Publication; create OUT : Publication from IN : Book; • A set of helpers that can be viewed as an ATL equivalent to Java methods equivalent to Java methods • A set of rules that defines the way target models are generated from source ones t d f / Faculteit Wiskunde en Informatica / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 21 9-1-2012 PAGE 22 Model transformations Model transformations • Libraries: • ATL helpers • The optional import section enables to declare which ATL • ATL helpers can be viewed as the ATL equivalent to Java libraries have to be imported methods • They make it possible to define factorized ATL code that can They make it possible to define factorized ATL code that can be called from different points of an ATL transformation • The declaration of an ATL library is achieved as follows: • Body of helpers is OCL code uses extensionless_library_file_name; uses extensionless library file name; • For example: uses strings; / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 23 / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 24
Model transformations Model transformations • An ATL helper is defined by the following elements: • Helper functions: y g • a name • A helper is an auxiliary function that computes a • a context type result needed in a rule − The context type defines the context in which this attribute is − The context type defines the context in which this attribute is helper context Book!Book def : getAuthors() : String = defined self.chapters-> − Optional collect(e | e.author)-> • a return value type • a return value type. asSet()-> S t() > − Note that, in ATL, each helper must have a return value iterate(authorName, acc : String = '' | • an OCL expression that represents the code of the ATL acc + if acc = '' if acc helper; helper; then authorName • an optional set of parameters, in which a parameter is else ' and ' + authorName identified by a couple (parameter name, parameter type). endif); / Faculteit Wiskunde en Informatica / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 25 9-1-2012 PAGE 26 Model transformations Model transformations Get the authors of • To iterate over a collection Select the chapters Filter duplicates each chapter each chapter source -> iterate(elem, var : Type = init_exp | body ) helper context Book!Book def : getAuthors() : String = self.chapters-> collect(e | e.author)-> • var is an accumulator which gets an initial value asSet()-> • elem is an iterator which iterates on each element of iterate(authorName; acc : String = '' | iterate(authorName; acc : String = | the collection acc + if acc = '' then authorName • For each iteration body is else ' and ' + authorName • evaluated and then endif); • used to update var Build a list / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 27 / Faculteit Wiskunde en Informatica 9-1-2012 PAGE 28
Recommend
More recommend