SLIDE 7 Model transformations
- An ATL helper is defined by the following elements:
y g
− The context type defines the context in which this attribute is − The context type defines the context in which this attribute is defined − Optional
- a return value type
- a return value type.
− Note that, in ATL, each helper must have a return value
- an OCL expression that represents the code of the ATL
helper; helper;
- an optional set of parameters, in which a parameter is
identified by a couple (parameter name, parameter type).
/ Faculteit Wiskunde en Informatica
PAGE 25 9-1-2012
Model transformations
- Helper functions:
- A helper is an auxiliary function that computes a
result needed in a rule
helper context Book!Book def : getAuthors() : String = self.chapters-> collect(e | e.author)-> S t() > asSet()-> iterate(authorName, acc : String = '' | acc + if acc = '' if acc then authorName else ' and ' + authorName endif);
/ Faculteit Wiskunde en Informatica
PAGE 26 9-1-2012
Model transformations
Select the chapters Get the authors of each chapter Filter duplicates
helper context Book!Book def : getAuthors() : String =
each chapter
self.chapters-> collect(e | e.author)-> asSet()-> iterate(authorName; acc : String = '' | iterate(authorName; acc : String = | acc + if acc = '' then authorName else ' and ' + authorName endif);
/ Faculteit Wiskunde en Informatica
PAGE 27 9-1-2012
Build a list
Model transformations
- To iterate over a collection
source -> iterate(elem, var : Type = init_exp | body )
- var is an accumulator which gets an initial value
- elem is an iterator which iterates on each element of
the collection
- For each iteration body is
- evaluated and then
- used to update var
/ Faculteit Wiskunde en Informatica
PAGE 28 9-1-2012