Group by name (to created Element) [message #1802881] |
Mon, 18 February 2019 13:10 |
Tai Ly Messages: 3 Registered: February 2019 |
Junior Member |
|
|
Hello dear community,
I'm working on a transformation from a Tree-Model A to another Tree-Model B, where in both cases Node-Elements are refering to itself bidirectional (parentNode, childNode).
Model A has multiple Nodes with the same name and B should create a parentNode to group them.
rule node2node{
from
--all Nodes which names occures more than 1 time
s_node: A!Node ( A!Node.allInstances() -> collect(n|n.name = s_node.name).size() > 1 )
to
parent: B!Node (
name <- s_node.name + ' Group',
childNode <- thisModule.resolveTemp(s_node, 'child')
),
child: B!Node(
name <- s_node.name,
additional_Information <- s_node.info --this distinguish them
)
}
the code is creating a new Element properly, but it only adds one Child to it (the corresponding one). Instead i wish to add/refer all Childs with the same name to a Parentnode.
we can assume that the guard is working (i have another one and this is just to simplify. The problem is the Child.
thank you very much,
Tai
|
|
|
Re: Group by name (to created Element) [message #1803073 is a reply to message #1802881] |
Thu, 21 February 2019 20:23 |
|
You can use a unique lazy rule in combination with the Canonic element design pattern:
-- @atlcompiler emftvm
-- @path TREE=/GroupByNameExample/metamodels/Tree.ecore
module GroupByName;
create OUT : TREE from IN : TREE;
--- Returns the Tuple value representation of the TREE!Node.
helper context TREE!Node def : toTuple : TupleType(name : String) =
Tuple{name = self.name};
rule Node {
from
s : TREE!Node
to
t : TREE!Node (
name <- s.name,
parent <- thisModule.Parent(s.toTuple)
)
}
unique lazy rule Parent {
from
s : TupleType(name : String)
to
t : TREE!Node (
name <- 'Parent of ' + s.name
)
}
I've attached an example eclipse project.
Cheers,
Dennis
|
|
|
|
Powered by
FUDForum. Page generated in 0.02041 seconds