EMF Compare - How to ignore identifiers

548 Views Asked by At

I have 2 models to compare. In my *.ecore model, I have an "Id" attribute and its ID property have been setted to true. I am using EcoreUtil.generateUUID() for unique ids.

In my case, I have one ready model and I am creating a new one in runtime. Therefore the ids are different from each other.

In developer guide of EMFCompare, they offer us to use UseIdentifiers.NEVER;

IEObjectMatcher matcher = DefaultMatchEngine.createDefaultEObjectMatcher(UseIdentifiers.NEVER);

Still, it produces mathces per node which have id like below:

Left object: DocModel.impl.ParagraphImpl@2767e23c (Id: _8pidAdVSEeSCK78kxjXrDg) (name: null) (rawText: Lorem ipsum ....)

Right object: DocModel.impl.ParagraphImpl@33bc72d1 (Id: _QSFJodrUEeSkqsl19NdwQQ) (name: null) (rawText: Lorem ipsum ....)

d.getKind(): CHANGE

I guess comparison sees them CHANGE bacause of different ids.

In short, I want to ignore Id attributes in comparison.

thanks and regards

1

There are 1 best solutions below

0
On

Before give you an answer, i want to fall into theory.

Emf compare uses two different ways of matching object. The first is Id functions, and another one is about calculation distance between objects in one group. By default, emf compare uses hybrid approach. If id function for element is available, than it will be invoked, otherwise it will match objects by nearest neighbour using distance functions. So, when you create matcher, you should specify strategy. In your case, you chose never to use id functions.

DefaultMatchEngine.createDefaultEObjectMatcher(UseIdentifiers.NEVER);

Actual comparison occurs not in match engine, but in diff engine. All you need is just extend DefaultDiffEngine and override createFeatureFilter method to provider you own FeatureFilter .