Example: Cloning EMF model elements with EOL

var emfTool = new Native("org.eclipse.epsilon.emc.emf.tools.EmfTool");
var ecoreUtil = emfTool.ecoreUtil;

var m = new Target!Model;

for (c in Source!Cloneable.all) {
  
  for (i in 1.to(5)) {
  
    // Create a clone of c. When created,
    // the clone doesn't belong to any model.
    var targetCloneable = ecoreUtil.copy(c);
    
    // Important: before accessing any properties of 
    // the cloned object, you need to add it to one 
    // of the involved models. For example, if the 
    // two following statements are put in reverse
    // order, it won't work.
    m.contents.add(targetCloneable);
    targetCloneable.name = targetCloneable.name + i;
  }
  
}
@namespace(uri="clone", prefix="clone")
package clone;

class Model {
   val Cloneable[*] contents;
}

class Cloneable {
   attr String name;
   val Detail[*] details;
}

class Detail {
   attr String key;
   attr String value;
}

Check out the code from the SVN:

  • go to the SVN repository
  • navigate to trunk/examples
  • check out the org.eclipse.epsilon.examples.clone project

Once you have checked out/imported the code, to run the example you need to go through the following steps:

  1. register any .ecore metamodels in the org.eclipse.epsilon.examples.clone project
  2. right click the .launch file in the org.eclipse.epsilon.examples.clone project
  3. select Run as... and click the first item in the menu that pops up

What's this?

In this example, we demonstrate how the EmfTool built-in tool can be used to perform deep-copy (cloning) of EMF model elements using EOL.

What are .emf files?

.emf files are Ecore metamodels expressed using the Emfatic textual syntax.

More examples...

Epsilon Object Language
Epsilon Transformation Language
Epsilon Generation Language
Epsilon Validation Language
Epsilon Merging Language
Epsilon Flock
Combining the Epsilon Languages
EuGENia
EUnit

Even more examples...

More examples are available in the examples folder of the SVN repository.