|
|
Re: Set MatchEngine ? [message #671637 is a reply to message #671616] |
Wed, 18 May 2011 14:35 |
js Missing name Messages: 73 Registered: July 2009 |
Member |
|
|
I now have:
DiffModel diff = null;
MatchModel match = null;
Map<String, Object> options = new HashMap<String, Object>();
// my own impl. that overrides the isSimilar method.
MyMatcherEngine myEngine = new MyMatcherEngine();
match = myEngine.contentMatch(left, right, options);
diff = DiffService.doDiff(match, false);
List<DiffElement> differences1 = new ArrayList<DiffElement>(diff.getOwnedElements());
System.out.println(differences1.size());
Even though I pass two identical EObjects the List<DiffElement> differences1 is not empty (my overridden isSimilar method returns true). Maybe it would be better to write my own DiffEngine instead and override the doDiff method:
public class MyDiffEngine extends GenericDiffEngine {
@Override
public DiffModel doDiff(MatchModel match, boolean threeWay) {
}
}
Default implementation:
public DiffModel doDiff(MatchModel match, boolean threeWay) {
matchCrossReferencer = new EcoreUtil.CrossReferencer(match) {
private static final long serialVersionUID = 1L;
/** initializer. */
{
crossReference();
}
};
final DiffModel result = DiffFactory.eINSTANCE.createDiffModel();
result.getLeftRoots().addAll(match.getLeftRoots());
result.getRightRoots().addAll(match.getRightRoots());
result.getAncestorRoots().addAll(match.getAncestorRoots());
DiffGroup diffRoot = null;
if (threeWay) {
diffRoot = doDiffThreeWay(match);
} else {
diffRoot = doDiffTwoWay(match);
}
result.getOwnedElements().add(diffRoot);
return result;
}
But whats the point of using emf-compare when I need to write all (override default methods) the match/diff logic myself? Of course I would be able to do something like this:
MyMatcherEngine myEngine = new MyMatcherEngine();
match = myEngine.contentMatch(left, right, options);
MyDiffEngine diffEngine = new MyDiffEngine();
diff = diffEngine.doDiff(match, false);
List<DiffElement> differences1 = new ArrayList<DiffElement>(diff.getOwnedElements());
System.out.println(differences1.size());
but I could do that as easily without introducing a dependency on emf-compare.
|
|
|
Re: Set MatchEngine ? [message #671935 is a reply to message #671637] |
Thu, 19 May 2011 11:54 |
|
Hi,
EMF Compare provides you with a framework that provide generic comparison engines, model loading help, integration with team repositories, the GUI integrated with the "classic" "compare with" actions of Eclipse... Many of these generic algorithms can be extended. Whether you wish to re-use some of the provided generic algorithms for your own comparison engine really is your call.
As for "how to provide your own engine", it depends on whether you call your code from and Eclipse plugin or from standalone code. If you call it from an Eclipse plugin, use the extension point org.eclipse.emf.compare.match.engine (and similarly for the diff engine, org.eclipse.emf.compare.diff.engine). If you call it from standalone code, then indeed calling the engines themselves like you did here is the way.
Laurent Goubet
Obeo
|
|
|
Powered by
FUDForum. Page generated in 0.04089 seconds