ATL Transformations

Complex Model Transformations

Master complex transformation scenarios including refining mode, multiple source/target models, and sophisticated rule coordination.

In this tutorial, you’ll tackle real-world transformation challenges that require advanced ATL features and careful architectural design.

You’ll learn how to handle model refactoring, multi-model transformations, and complex metamodel mappings.

60 mins Estimated Time

Section 1

Refining Mode Transformations

Refining mode enables in-place transformations where unmatched elements are automatically copied to the output. This is useful for model refactoring and partial transformations.

Declare refining mode with refining instead of create in the module header.

Step 1

Understand refining mode syntax.

Refining mode uses refining and automatically copies unmatched elements.

RefiningExample.atl
1-- @path Model=/Model/Model.ecore
2
3module RefiningExample;
4refining Model;
5
6-- Refining mode: unmatched elements copied automatically
7-- Only transform specific elements

Step 2

Refactor model elements selectively.

Only matched elements are transformed; others pass through unchanged.

RefiningExample.atl
1-- @path Model=/Model/Model.ecore
2
3module RefiningExample;
4refining Model;
5
6-- Only transform elements matching criteria
7rule UpdateSpecificElements {
8 from
9 s: Model!Element (s.version < 2)
10 to
11 t: Model!Element (
12 name <- s.name,
13 version <- 2
14 )
15}

Step 3

Combine matched and lazy rules in refining mode.

Use lazy rules to create new elements whilst refactoring existing ones.

RefiningExample.atl
1-- @path Model=/Model/Model.ecore
2
3module RefiningExample;
4refining Model;
5
6-- Lazy rule in refining mode
7lazy rule CreateSummary {
8 from
9 s: Model!Element
10 to
11 t: Model!Summary (
12 elementName <- s.name
13 )
14}

Step 4

Build a complete refactoring transformation.

This transformation demonstrates practical model refactoring using refining mode.

RefiningExample.atl
1-- @path Model=/Model/Model.ecore
2
3module RefiningExample;
4refining Model;
5
6-- Helper to identify elements needing refactoring
7helper context Model!Element def: needsRefactoring(): Boolean =
8 self.deprecated = true;
9
10-- Only refactor deprecated elements
11rule RefactorDeprecated {
12 from
13 s: Model!Element (s.needsRefactoring())
14 to
15 t: Model!Element (
16 name <- 'Updated_' + s.name,
17 deprecated <- false
18 )
19}

Section 2

Multi-Model Transformations

Complex transformations may consume multiple source models or produce multiple target models. ATL supports arbitrary source/target model configurations.

Declare multiple models in the module header and reference them by name in rules.

Step 1

Set up multiple source models.

Transformations can read from multiple source models simultaneously.

MultiModelExample.atl
1-- @path ModelA=/ModelA/ModelA.ecore
2-- @path ModelB=/ModelB/ModelB.ecore
3-- @path Target=/Target/Target.ecore
4
5module MultiModelExample;
6create OUT: Target from INA: ModelA, INB: ModelB;
7
8-- Access elements from both source models
9-- Use INA!Type and INB!Type to distinguish sources

Step 2

Generate multiple target models.

Rules can create elements in different target models based on transformation logic.

MultiModelExample.atl
1-- @path Source=/Source/Source.ecore
2-- @path TargetA=/TargetA/TargetA.ecore
3-- @path TargetB=/TargetB/TargetB.ecore
4
5module MultiModelExample;
6create OUTA: TargetA, OUTB: TargetB from IN: Source;
7
8-- Create elements in first target model
9rule ToTargetA {
10 from
11 s: Source!Element
12 to
13 t: OUTA!ItemA (
14 name <- s.name
15 )
16}
17
18-- Create elements in second target model
19rule ToTargetB {
20 from
21 s: Source!Element
22 to
23 t: OUTB!ItemB (
24 title <- s.name
25 )
26}

Step 3

Coordinate rules across models.

Complex transformations coordinate multiple rules that work across different models.

MultiModelExample.atl
1-- @path ModelA=/ModelA/ModelA.ecore
2-- @path ModelB=/ModelB/ModelB.ecore
3-- @path Target=/Target/Target.ecore
4
5module MultiModelExample;
6create OUT: Target from INA: ModelA, INB: ModelB;
7
8-- Coordinate information from multiple sources
9rule CoordinatedTransform {
10 from
11 a: ModelA!ElementA
12 to
13 t: Target!Item (
14 nameFromA <- a.name,
15 relatedB <- INB!ElementB.allInstances()
16 ->select(b | b.refId = a.id)
17 ->collect(b | b.name)
18 )
19}

Step 4

Build a complete multi-model transformation.

This transformation demonstrates sophisticated multi-model processing.

MultiModelExample.atl
1-- @path ModelA=/ModelA/ModelA.ecore
2-- @path ModelB=/ModelB/ModelB.ecore
3-- @path Target=/Target/Target.ecore
4
5module MultiModelExample;
6create OUT: Target from INA: ModelA, INB: ModelB;
7
8-- Transform from first source model
9rule TransformA {
10 from
11 s: ModelA!ElementA
12 to
13 t: Target!Item (
14 name <- s.name,
15 source <- 'ModelA'
16 )
17}
18
19-- Transform from second source model
20rule TransformB {
21 from
22 s: ModelB!ElementB
23 to
24 t: Target!Item (
25 name <- s.name,
26 source <- 'ModelB'
27 )
28}
29
30-- Combine information from both models
31rule CombineModels {
32 from
33 a: ModelA!ElementA,
34 b: ModelB!ElementB
35 to
36 t: Target!Combined (
37 nameA <- a.name,
38 nameB <- b.name,
39 combined <- a.name + ' + ' + b.name
40 )
41}

Check Your Understanding

Question 1 of 3

What is refining mode used for?

Question 2 of 3

Can you mix refining mode with lazy rules?

Question 3 of 3

How do you specify which target model to create elements in?

Performance Optimisation

Optimise ATL transformations for better performance with large models and complex metamodels.