Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/org.eclipse.qvtd.atl.tests/models/tree2list/Tree2List.atl')
-rw-r--r--tests/org.eclipse.qvtd.atl.tests/models/tree2list/Tree2List.atl34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/org.eclipse.qvtd.atl.tests/models/tree2list/Tree2List.atl b/tests/org.eclipse.qvtd.atl.tests/models/tree2list/Tree2List.atl
new file mode 100644
index 000000000..d781595a1
--- /dev/null
+++ b/tests/org.eclipse.qvtd.atl.tests/models/tree2list/Tree2List.atl
@@ -0,0 +1,34 @@
+-- @name Tree structure to List structure
+-- @version 1.0
+-- @domains
+-- @authors Cyril Faure
+-- @date 01/06/2007
+-- @description "toy example" of model transformation usually made with a DFS (Depth First Search) imperative algorithms
+-- @see http://en.wikipedia.org/wiki/Depth-first_search
+-- @path MMTree=/org.eclipse.qvtd.atl.tests/models/tree2list/MMTree.ecore
+-- @path MMElementList=/org.eclipse.qvtd.atl.tests/models/tree2list/MMElementList.ecore
+
+module Tree2List;
+create elmList : MMElementList from aTree : MMTree;
+
+uses Lib4MMTree;
+
+-- we want to process the tree via DFS and create an ordered list containing :
+-- all big leafs, then all medium leafs, then all small leafs. We add the
+-- constraint we want all three "sublists" to be ordered on the DFS traversal order
+-- Note : the nodes (other than the tree root) are not kept in the destination model
+
+-- The transformation is done with only one matched rule. For each element of its elements reference, we create a MMElementList!CommonElement.
+-- Each element of this list is computed via a distinct keyword which creates a CommonElement for each Leaf of a list we compute via an helper.
+rule TreeNodeRoot2RootElement {
+ from -- should be unique
+ rt : MMTree!Node (rt.isTreeNodeRoot())
+ to
+ lstRt : MMElementList!RootElement (
+ name <- rt.name,
+ elements <- elmLst
+ ),
+ elmLst : distinct MMElementList!CommonElement foreach(leaf in rt.getLeavesInOrder())(
+ name <- leaf.name
+ )
+} \ No newline at end of file

Back to the top