Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Match rule returning existing object ?
Match rule returning existing object ? [message #1803680] Wed, 06 March 2019 16:55 Go to next message
G LG is currently offline G LGFriend
Messages: 4
Registered: March 2019
Junior Member
Is it possible to write a matching rule that returns an existing object (result of another rule) ?

Suppose I have the following source metamodel:
SrcAbs <|- SrcA
SrcAbs <|- SrcB { elems : SrcAbs* }
SrcAbs <|- SrcC { root : SrcAbs }
...
One abstract class (SrcAbs) and many classes (SrcA, SrcB, ...) inheriting from the abstract class, and some of which contains attributes pointing to one or many elements of the abstract class type.

The target metamodel is similarly structured:
TgtAbs <|- TgtA
TgtAbs <|- TgtB { elems : TgtAbs* }
TgtAbs <|- TgtC { root : TgtAbs }

In the case of the transformation of SrcB, I want to retrun a TgtA if elems is empty, a TgtB if elems has more than 1 elements, and the transformation of elems.first() if elems has exactly 1 element.

rule A {
from f : ...!SrcB ( f.elems.isEmpty() )
to t : ...!TgtA
}
rule B {
from f : ...!SrcB ( f.elems.size() > 1 )
to t : ...!TgtB ( elems <- f.elems )
}

Can I write a matching rule to handle the case f.elems.size() = 1 ?

If not, what is the best way to handle this case if:
- I'm writing a normal module (Src -> Tgt) ?
- I'm writing a refining module (where I want only to replace TgtB with 1 element in elems by this element) ?

Thanks
Re: Match rule returning existing object ? [message #1804229 is a reply to message #1803680] Wed, 20 March 2019 19:39 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 581
Registered: September 2012
Location: Belgium
Senior Member

If you want to map multiple input elements to the same output element, you can use the Canonic Element pattern.

Cheers,
Dennis
Re: Match rule returning existing object ? [message #1806531 is a reply to message #1804229] Fri, 10 May 2019 08:43 Go to previous messageGo to next message
G LG is currently offline G LGFriend
Messages: 4
Registered: March 2019
Junior Member
Hi,

Thank you for your answer. However, I do not see how to use the Canonic Element pattern in my case.

What I want is, for example, the following transformation : "(C : SrcC)-root->( (B : SrcB)-elems->{ (A : SrcA) } )" into "(C' : TgtC)-root->( (A' : TgtA) )" where (O : T)-f->X means object O of type T with field f referencing X.

The semantics of the rule for SrcB with only 1 element in elems would be something like :
rule B {
from f : ...!SrcB ( f.elems.size() = 1 )
to [do not create a new object but use/return the result of the transformation of f.elems.get(0)]
}

Thanks
Re: Match rule returning existing object ? [message #1806843 is a reply to message #1806531] Thu, 16 May 2019 07:01 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 581
Registered: September 2012
Location: Belgium
Senior Member

If you want to "skip over" certain input elements, perhaps this transformation can provide some inspiration:

https://git.eclipse.org/c/mmt/org.eclipse.atl.git/tree/plugins/org.eclipse.m2m.atl.emftvm.compiler/transformations/InlineCodeblocks.atl?id=2bcbeec856bbd9b2488c17c30ffd34c5449505a0

It flattens nested blocks of instructions, where possible, and thereby "skips over" some input elements. It does differ in that this is a refining mode transformation, however.


Cheers,
Dennis
Re: Match rule returning existing object ? [message #1806845 is a reply to message #1806843] Thu, 16 May 2019 07:21 Go to previous message
G LG is currently offline G LGFriend
Messages: 4
Registered: March 2019
Junior Member
Hi,

It seems to be what I was looking for. I'll dig into it.

Thank you
Previous Topic:HOT transformation examples
Next Topic:extract ATL transformation from ecore model
Goto Forum:
  


Current Time: Sat Nov 11 08:19:54 GMT 2023

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

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

Back to the top