Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Create new element in target model
Create new element in target model [message #1847646] Tue, 02 November 2021 23:14 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi all,

Considering we have the following two metamodels.

Metamodel A used as source metamodel:

index.php/fa/41244/0/

and metamodel C as target metamodel:

index.php/fa/41245/0/

As you can see, the target metamodel contains one extra elements "ElementPool" that is not present in the source metamodel. In order to transform Element2Element, I first need to create "ElementPool" and then transform elements and put "Element" as a child of "ElementPool".

I wrote the following transformation:

modeltype A uses metamodelA('http://www.example.org/metamodelA');
modeltype C uses metamodelC('http://www.example.org/metamodelC');


transformation test(in srcModel:A, out trgModel:C);

main() {
srcModel.rootObjects()[A::Map] -> map Map2Map();
}
mapping Map :: Map2Map() : C::Map 
{
var pool : C::ElementPool;
elementpool := pool;
pool.elements := self.element.map toElement();
}

mapping Element:: toElement() : C::Element
{
name:=self.name;
}


But, the issue is that "ElementPool" is still not being created. Is there another syntax to it, or the logic is not right?

Thank you in advance!
Re: Create new element in target model [message #1847650 is a reply to message #1847646] Wed, 03 November 2021 05:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It's pretty much the same as Java. If you declare a variable that doesn't make it exist. You need a new expression to create it.

Same in QVTo, you need an object creation, either explicitly via an object expression or implicitly as part of a mapping.

(It would be better if QVTo, like JDT diagnosed the problem by reporting that pool was not adequately initialized.)

Regards

Ed Willink
Re: Create new element in target model [message #1847660 is a reply to message #1847650] Wed, 03 November 2021 07:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Quote:
(It would be better if QVTo, like JDT diagnosed the problem by reporting that pool was not adequately initialized.)


https://bugs.eclipse.org/bugs/show_bug.cgi?id=577023 raised.

Regards

Ed Willink
Re: Create new element in target model [message #1847661 is a reply to message #1847650] Wed, 03 November 2021 08:05 Go to previous message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 115
Registered: April 2011
Senior Member
Ed Willink wrote on Wed, 03 November 2021 01:49
Same in QVTo, you need an object creation, either explicitly via an object expression or implicitly as part of a mapping.
Right. A third option is invoking a constructor, which must be declared first.
Previous Topic:Can we map two abstract classes?
Next Topic:Compiling performance
Goto Forum:
  


Current Time: Sat Apr 27 02:03:22 GMT 2024

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

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

Back to the top