Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xtext] Isn't a copy operation side-effect free?
[Xtext] Isn't a copy operation side-effect free? [message #488001] Fri, 25 September 2009 09:23 Go to next message
smoking  is currently offline smoking Friend
Messages: 1
Registered: September 2009
Junior Member
Hello everybody!

I just discovered something I didn't know.. I have something like this in my code:

create ClassA newObj copyObj(ClassB o):
newObj.setAssociation(o.ass)->
newObj;


where ass represents an association (having containment=true in the metamodel) with another class, let's say classC. My problem is that after setAssociation() has been performed, the association in o is set to null, while I want this operation to be side-effect free..

Can you hint me a workaround please?

Many thanks!
Bye!
Re: [Xtext] Isn't a copy operation side-effect free? [message #488060 is a reply to message #488001] Fri, 25 September 2009 13:19 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi smoking,

as an EObject may only be contained in one and only one container, you
modify it by setAssociation(o.ass) which puts it into another container.

You may want to EcoreUtil.copy() your model before you perform the
transformation.

Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

smoking schrieb:
> Hello everybody!
>
> I just discovered something I didn't know.. I have something like this
> in my code:
>
> create ClassA newObj copyObj(ClassB o):
> newObj.setAssociation(o.ass)->
> newObj;
>
> where ass represents an association (having containment=true in the
> metamodel) with another class, let's say classC. My problem is that
> after setAssociation() has been performed, the association in o is set
> to null, while I want this operation to be side-effect free..
> Can you hint me a workaround please?
>
> Many thanks!
> Bye!
Previous Topic:Check: Live Validation
Next Topic:[Announce] M2T XPAND 0.8.0M2 is available
Goto Forum:
  


Current Time: Thu Apr 18 05:18:04 GMT 2024

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

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

Back to the top