Example: Compare, validate and merge OO models


  • CompareSimpleOO.ecl
  • ValidateSimpleOO.evl
  • MergeSimpleOO.eml
  • Get it!
rule Models 
  match l : Left!Model with r : Right!Model {
  compare : true
}

rule Class 
  match l : Left!Class with r : Right!Class {

  compare : l.name = r.name
}
context SimpleOO!Class {
  constraint BothAbstractOrNot {    
    guard : self.getMatching().isDefined()    
    check : self.getMatching().isAbstract = self.isAbstract  
    message : 'Inconsistent value in feature "abstract" ' 
      + 'of class ' + self.name
  }
}

@cached
operation SimpleOO!Class getMatching() : Any {
  var match := matchTrace.matches.selectOne
    (m|m.left = self or m.right = self);
  if (not match.isDefined()) { return null; }
  if (match.left = self) { return match.right; }
  else { return match.left; }
}
rule MergeModel
  merge l : Left!Model with r : Right!Model into t : Target!Model {
  
  t.name := l.name + ' and ' + r.name;
  t.contents ::= l.contents + r.contents;  
}

rule MergeClass
  merge l : Left!Class with r : Right!Class  into t : Target!Class {
  
  t.name := l.name;
  t.isAbstract := l.isAbstract;
}

rule CopyModel
  transform s : Source!Model to t : Target!Model {
  
  t.contents ::= s.contents;
}
rule CopyClass
  transform s : Source!Class to t : Target!Class {
  
  t.name := s.name;
  t.isAbstract := s.isAbstract;
}


There are two ways to get the code of this example:

  1. download the following zip archive(s), extract them and import them as new Eclipse projects
  2. or check out the code from the SVN
    • go to the SVN repository
    • navigate to trunk/examples
    • check out the org.eclipse.epsilon.examples.oomerging project

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

  1. right click the .launch file in the org.eclipse.epsilon.examples.oomerging project
  2. select Run as... and click the first item in the menu that pops up