Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Deep copy of model element
Deep copy of model element [message #1283477] Thu, 03 April 2014 13:07 Go to next message
Vlad Acretoaie is currently offline Vlad AcretoaieFriend
Messages: 95
Registered: April 2014
Member
I am an Epsilon beginner, and am currently getting started by writing the classic Pull Up Attribute refactoring in ETL on a UML Class Diagram. My model is a UML model ("source.uml") created using Papyrus.

This is an endogenous transformation and I'm currently attempting an out-place approach - generating a separate output model "target.uml". As a first step, I should first be able to do something simple: copy the model in "source.uml" to "target.uml". However, I got stuck at this point. It is not clear to me whether I need to write an ETL rule for every model element type in "source.uml" - in UML, these can be quite a lot. Furthermore, do I then need to manually copy each property of each model element withing this rule? This seems like a lot of work, and also seems to lose the model structure - if I have a rule for instances of Property, Properties are created in the target model separately from any Class element.

Is there some kind of "deep copy" operator to allow copying e.g. a Class in the source model to the target model together with all of its Properties? Or just copy an entire Model as it is?

Thanks in advance,
Vlad
Re: Deep copy of model element [message #1283771 is a reply to message #1283477] Thu, 03 April 2014 20:11 Go to previous messageGo to next message
Dimitris Kolovos is currently online Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Vlad,

You can use EcoreUtil to deep-copy elements as follows:

var emfTool : new Native("org.eclipse.epsilon.emc.emf.tools.EmfTool");
var source = <the model element you need to copy>;
var copy = emfTool.getECoreUtil().copy();

Please see Window->Show View->Tools for additional native tools and [1] for instructions on how to develop a custom one.

Cheers,
Dimitris

[1] http://eclipse.org/epsilon/doc/articles/call-java-from-epsilon/
Re: Deep copy of model element [message #1284465 is a reply to message #1283771] Fri, 04 April 2014 14:08 Go to previous messageGo to next message
Vlad Acretoaie is currently offline Vlad AcretoaieFriend
Messages: 95
Registered: April 2014
Member
Thank you for the answer. However, I am now in doubt as to how this approach can be used. The following rule generates an error ("Variable 'target' is read-only"):

rule DeepCopy
transform source : Source!Class
to target : Target!Class {

var emfTool : new Native("org.eclipse.epsilon.emc.emf.tools.EmfTool");
target = emfTool.getECoreUtil().copy(source);
}

If assigning a value to the target element is in general not possible, I guess the deep copy does not help in this context.

Am I maybe better off using EOL for my refactoring?

Cheers,
Vlad
Re: Deep copy of model element [message #1284547 is a reply to message #1284465] Fri, 04 April 2014 15:51 Go to previous messageGo to next message
Dimitris Kolovos is currently online Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Vlad,

Off the top of my head, a workaround you could use would be to define target as a sequence and then add the cloned element to it i.e.

rule DeepCopy
transform source : Source!Class
to target : Sequence {
var emfTool : new Native("org.eclipse.epsilon.emc.emf.tools.EmfTool");
var target = emfTool.getECoreUtil().copy(source);
targets.add(target);
// Add the new element to the Target resource
// Since you're adding elements to the resource directly you'll need to un-tick the cache
// option in Target's model configuration dialog
Target.resource.contents.add(target);
}

Alternatively, using EOL would also make sense.

Cheers,
Dimitris

[Updated on: Fri, 04 April 2014 15:54]

Report message to a moderator

Re: Deep copy of model element [message #1288400 is a reply to message #1284547] Tue, 08 April 2014 14:26 Go to previous messageGo to next message
Vlad Acretoaie is currently offline Vlad AcretoaieFriend
Messages: 95
Registered: April 2014
Member
Hi Dimitris,

I have tried defining target as a Sequence, as you suggested. However, in this case the following assignment produces an ArrayStoreException (java.lang.ArrayStoreException: org.eclipse.epsilon.eol.types.EolSequence):

Target.resource.contents.add(targets);


I am a bit surprised by how tricky it is to produce an unchanged copy of a model in ETL, considering this is probably the most basic out-place transformation. I get the feeling I am probably missing something in my understanding of ETL.

Cheers,
Vlad
Re: Deep copy of model element [message #1288480 is a reply to message #1288400] Tue, 08 April 2014 15:55 Go to previous message
Dimitris Kolovos is currently online Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Vlad,

Since targets is a sequence, you should probably call addAll(...) instead of add(...). ETL is geared towards mapping transformations. I'm starting to think that Flock (see Chapter 10 of the Epsilon book [1]) may be a better fit for your use case.

Cheers,
Dimitris

[1] http://eclipse.org/epsilon/doc/book/
Previous Topic:Copying object properties
Next Topic:[Eugenia-newbie]: Compile errors in generated code?
Goto Forum:
  


Current Time: Fri Apr 19 12:33:00 GMT 2024

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

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

Back to the top