Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Refining Mode: Clone Element and add it to same parent
Refining Mode: Clone Element and add it to same parent [message #1737868] Wed, 13 July 2016 15:33 Go to next message
Sven L. is currently offline Sven L.Friend
Messages: 16
Registered: May 2012
Junior Member
Hi,

I'm using ATL EMFTVM in refining mode, and I can't figure out how to add a cloned element to the same parent as the source element. Let's say this is the rule:

rule CopyElement {
    from s : MM!Element
    to 
        t1 : MM!Element,
        t2 : MM!Element (
            -- copy all the things
       )
}


When I run this I get a copy of the source element, but it is located outside any container on the same level as the root container. I tried to add it to the correct container by using a do block:

do {
    s.refImmediateComposite().elements <- s.refImmediateComposite().elements->append(t2);
}


However, this does nothing, only add the copy of the last matched element to the parent container.

What would be the correct way to do this?

Edit* Some more insight on the behavior:
The rule above is matched several times in my case, and only in the last execution the element is added to the parent container.
It is a large container, so I didn't notice at first. All, but the last copied element, are outside the root container...

[Updated on: Fri, 15 July 2016 13:51]

Report message to a moderator

Re: Refining Mode: Clone Element and add it to same parent [message #1738073 is a reply to message #1737868] Fri, 15 July 2016 14:58 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 373
Registered: September 2012
Location: Belgium
Senior Member

In EMFTVM refining mode, the execution of all assignments is postponed until the end of each phase ("apply" for the to-block or "post-apply" for the do-block). As a result,
s.refImmediateComposite().elements
will always evaluate to the same state throughout the entire execution phase. This is done to uphold ATL's principle that says rule execution order does (should) not matter. Creating execution order dependencies between rules typically kills maintainability of your transformation code, so this is not the way to go.

The preferred way to assign the "elements" property of the container is inside its own rule, with a single assignment. You can use the "resolveTemp" operation to collect the extra elements:
elements <- s.elements->union(s.elements->collect(e | thisModule.resolveTemp(e, 't2'))


Cheers,
Dennis
Re: Refining Mode: Clone Element and add it to same parent [message #1738207 is a reply to message #1738073] Mon, 18 July 2016 07:23 Go to previous message
Sven L. is currently offline Sven L.Friend
Messages: 16
Registered: May 2012
Junior Member
Hi Dennis,

thank you for your reply.
That was, what I was looking for. Just to add something for completeness: If I only want to copy certain elements I also have to add the condition to the root rule.

It now looks like this:

elements <- s.elements -> union(s.elements -> select(e | condition) -> collect(e | thisModule.resolveTemp(e, 't2')))
Previous Topic:[ATL] Unique rule has double output
Next Topic:containment references cannot span across models
Goto Forum:
  


Current Time: Mon Sep 24 13:16:54 GMT 2018

Powered by FUDForum. Page generated in 0.01675 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top