Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » How to create n target-object from one source object(where the amount n is defined by an attribute of the source object)
How to create n target-object from one source object [message #1504476] Tue, 09 December 2014 09:37 Go to next message
Thomas Busch is currently offline Thomas BuschFriend
Messages: 23
Registered: November 2014
Junior Member
Hi,

how hard can it be? Thats what I thought, but now I am stuck at a seemingly easy problem:

I have a source object with the attribute "amount". I want to transform it to "amount"-many target-objects.

I wonder if this is even possible in the imperative code-part.

I would be very thankful for some help!

Regards

Thomas

[Updated on: Tue, 09 December 2014 09:38]

Report message to a moderator

Re: How to create n target-object from one source object [message #1505057 is a reply to message #1504476] Tue, 09 December 2014 20:14 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

This can be done as follows:

rule Parent {
  from
    s : SRC!Element
  to
    t : TGT!Parent (
      children <- s.createChildren(s.amount)
    )
}

helper context SRC!Element def : createChildren(amount : Integer) : Sequence(TGT!Child) =
  if amount < 1 then
    Sequence{}
  else
    self.createChildren(amount - 1)->including(thisModule.CreateChild(self))
  endif;

lazy rule CreateChild {
  from
    s : SRC!Element
  to
    t : TGT!Child
}


With ATL/EMFTVM, this can be shortened to:

rule Parent {
  from
    s : SRC!Element
  to
    t : TGT!Parent (
      children <- Sequence{}->includingRange(1, s.amount)->collect(i | thisModule.CreateChild(s))
    )
}

lazy rule CreateChild {
  from
    s : SRC!Element
  to
    t : TGT!Child
}


Cheers,
Dennis
Re: How to create n target-object from one source object [message #1511795 is a reply to message #1505057] Mon, 15 December 2014 07:02 Go to previous message
Thomas Busch is currently offline Thomas BuschFriend
Messages: 23
Registered: November 2014
Junior Member
thank you!
It works great! It also fixed another problem I had.
Previous Topic:Setting a value for a variable from the type NMTOKENS
Next Topic:finding two source-objects with same names
Goto Forum:
  


Current Time: Thu Mar 28 19:15:30 GMT 2024

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

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

Back to the top