How to use EMF Diff/Merge programmatically [message #1737860] |
Wed, 13 July 2016 14:48 |
Daniel Szabo Messages: 6 Registered: July 2016 |
Junior Member |
|
|
Hello,
I want to use programmatically EMF Diff/Merge for my EMF model project to make a specific diff and merge plugin. I found help for it only in its javadoc and on this site: http://wiki.eclipse.org/EMF_DiffMerge/Programmatic_Usage
but it's not detailed enough for me.
I tried an example code that is written on the site above, but I got in trouble about how could I get the differences programmatically (in what form does it give the differences and how could I understand and interpret these) that EMF Diff/Merge gives and how could I work with its result.
My example code is this (according to that site):
ResourceSet resSet = new ResourceSetImpl();
Resource resource = resSet.getResource(URI.createURI("grafok/MyGraph.xmi"), true);
Resource resource2 = resSet.getResource(URI.createURI("grafok/MyGraph2.xmi"), true);
IEditableModelScope targetScope = new FragmentedModelScope(resource, false);
IEditableModelScope referenceScope = new FragmentedModelScope(resource2, false);
IComparison comparison = new EComparisonImpl(targetScope, referenceScope);
comparison.compute(new DefaultMatchPolicy(), new DefaultDiffPolicy(), new DefaultMergePolicy(), new NullProgressMonitor());
Collection<IDifference> differences = comparison.getRemainingDifferences();
Can anyone help about it or link a more detailed and understandable documentation about EMF Diff/Merge?
Thanks in advance
|
|
|
|
|
|
Re: How to use EMF Diff/Merge programmatically [message #1738265 is a reply to message #1738237] |
Mon, 18 July 2016 14:08 |
Daniel Szabo Messages: 6 Registered: July 2016 |
Junior Member |
|
|
I made the IDs (EInt type) myself and made it unique. Now I overrided the getIntrinsicID method in the ConfigurableMatchPolicy class and made it return the elements' ID. Is it a good solution? With this only one type (from my metamodel) of elements got mapped after I checked it, the others didn't.
Anyway I also don't really understand the structure of the mapping because the getAllContents(Role.TARGET) method gives nothing but the getAllContents(Role.REFERENCE) gives the expected IMatch elements but not all is matched well as mentioned above.
[Updated on: Mon, 18 July 2016 14:09] Report message to a moderator
|
|
|
|
|
|
|
|
Re: How to use EMF Diff/Merge programmatically [message #1738426 is a reply to message #1738382] |
Tue, 19 July 2016 16:46 |
Olivier Constant Messages: 106 Registered: January 2012 |
Senior Member |
|
|
In that case, you can redefine method "getMatchID" of DefaultMatchPolicy so that it returns, for example, the String concatenation of the (qualified) type name and the ID value. The idea is that two elements match if and only if their match IDs are equal.
Other than that, is there any reason why you have such a specific, per-type identification mechanism? If you want to have, e.g., version control of your models, a 'classical' way would be to have a root metaclass in the type hierarchy of your metamodel owning an ID attribute of type EString, and a customized constructor implementation in the corresponding Java class that sets the value of the ID attribute to, for example, EcoreUtil.generateUUID().
|
|
|
Powered by
FUDForum. Page generated in 0.03517 seconds