Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF Diff/Merge » How to use EMF Diff/Merge programmatically
How to use EMF Diff/Merge programmatically [message #1737860] Wed, 13 July 2016 14:48 Go to next message
Daniel Szabo is currently offline Daniel SzaboFriend
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 #1738053 is a reply to message #1737860] Fri, 15 July 2016 12:05 Go to previous messageGo to next message
Daniel Szabo is currently offline Daniel SzaboFriend
Messages: 6
Registered: July 2016
Junior Member
I gave two models (which are the same) as the resources but still got the number of the elements of the 2 models as result of the differences' number by default. So it means it didnt match any of them despite the elements are same in the 2 models. I think it doesnt make matching on the right attribute for example on the IDs. In addition I queried the IMatch elements of the comparison and the target and reference object of them, and every IMatch has only target or only reference object which also means there weren't any matching between the 2 models I think. I also dont understand then why were these IMatch elements created.

I know I'm doing these wrongly yet, but I cant really figure out how it works (I'm also reading its javadoc but without much success yet). Could you please help about it or just about how should I start using this tool?
Re: How to use EMF Diff/Merge programmatically [message #1738231 is a reply to message #1738053] Mon, 18 July 2016 09:45 Go to previous messageGo to next message
Daniel Szabo is currently offline Daniel SzaboFriend
Messages: 6
Registered: July 2016
Junior Member
The Extrinsic ID and Intrinsic ID are also null of my model elements so I think this is the reason why werent any of the elements matched between the two model instances. How could I set any of the MatchCriterionKind enum well in order to make working matchings between the models?
Re: How to use EMF Diff/Merge programmatically [message #1738237 is a reply to message #1738231] Mon, 18 July 2016 10:37 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 392
Registered: December 2015
Senior Member
On 18-Jul-16 11:45, Daniel Szabo wrote:
> Extrinsic ID and Intrinsic ID are also null of my model elements so I
> think this is the reason why werent any of the elements matched between
> the two model instances. How could I set any of the MatchCriterionKind
> enum well in order to make working matchings between the models?

If your elements have no IDs, how would you ever want to match two
elements? What "defines" the identity of your model elements?

Felix
Re: How to use EMF Diff/Merge programmatically [message #1738265 is a reply to message #1738237] Mon, 18 July 2016 14:08 Go to previous messageGo to next message
Daniel Szabo is currently offline Daniel SzaboFriend
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 #1738268 is a reply to message #1738265] Mon, 18 July 2016 14:29 Go to previous messageGo to next message
Stephane Bouchet is currently offline Stephane BouchetFriend
Messages: 280
Registered: July 2009
Senior Member
Hi,

You should try to override only the getMatchID(EObject, IModelScope) method to return the string representation of your unique ID. This is the first method to be called by the framework to determine the unique id to match elements.
you can also put a breakpoint here to see if the same EObject from the target and the reference resource have the same ID returned.
Re: How to use EMF Diff/Merge programmatically [message #1738283 is a reply to message #1738268] Mon, 18 July 2016 16:16 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 106
Registered: January 2012
Senior Member
If you defined your own ID attribute in your metamodel, it would be good to set its ID property to true.
http://download.eclipse.org/modeling/emf/emf/javadoc/2.4.3/org/eclipse/emf/ecore/EAttribute.html#isID%28%29
Then there are chances that it works out of the box with the DefaultMatchPolicy.
Re: How to use EMF Diff/Merge programmatically [message #1738339 is a reply to message #1738283] Tue, 19 July 2016 07:43 Go to previous messageGo to next message
Daniel Szabo is currently offline Daniel SzaboFriend
Messages: 6
Registered: July 2016
Junior Member
Olivier Constant wrote on Mon, 18 July 2016 16:16
If you defined your own ID attribute in your metamodel, it would be good to set its ID property to true.
http://download.eclipse.org/modeling/emf/emf/javadoc/2.4.3/org/eclipse/emf/ecore/EAttribute.html#isID%28%29
Then there are chances that it works out of the box with the DefaultMatchPolicy.


How should I do this? Because my ID is type of EInt. (Anyway, I have set now this own ID to be "ID" and to be uniqe in the metamodel editor (which looks like a class diagram editor) but I don't see the result of this in the regenerated model code.)

Furthermore, how can I make the match policy to distinguish the different types of the metamodel and match its instance model elements even if they have the same ID. I mean that I have Node class and Edge class and when a Node instance element has the same ID as an Edge element then the match policy take them separately and match the corresponding elements with each other. (But now in my case if 2 different type of elements have the same ID then only one of them will be matched.)
Re: How to use EMF Diff/Merge programmatically [message #1738343 is a reply to message #1738339] Tue, 19 July 2016 07:56 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 392
Registered: December 2015
Senior Member
On 19-Jul-16 09:43, Daniel Szabo wrote:
> Olivier Constant wrote on Mon, 18 July 2016 16:16
>> If you defined your own ID attribute in your metamodel, it would be
>> good to set its ID property to true.
>> http://download.eclipse.org/modeling/emf/emf/javadoc/2.4.3/org/eclipse/emf/ecore/EAttribute.html#isID%28%29
>>
>> Then there are chances that it works out of the box with the
>> DefaultMatchPolicy.
>
>
> How should I do this? Because my ID is type of EInt.
In the Ecore model editor you select the property and set its "ID"
attribute to true.


(Anyway, I have set
> now this own ID to be "ID" and to be uniqe in the metamodel editor
> (which looks like a class diagram editor) but I don't see the result of
> this in the regenerated model code.)
You should see a change in the generated package code.


> Furthermore, how can I make the match policy to distinguish the
> different types of the metamodel and match its instance model elements
> even if they have the same ID.

I am not sure if DiffMerge detects a 'change of type' for two elements
with matching ID.. IIRC it does not.


Felix
Re: How to use EMF Diff/Merge programmatically [message #1738382 is a reply to message #1738343] Tue, 19 July 2016 11:19 Go to previous messageGo to next message
Daniel Szabo is currently offline Daniel SzaboFriend
Messages: 6
Registered: July 2016
Junior Member
Felix Dorner wrote on Tue, 19 July 2016 07:56

I am not sure if DiffMerge detects a 'change of type' for two elements
with matching ID.. IIRC it does not.


Felix


This is not what I want. I mean that in an instance model of mine has more different types (classes) and their ID can be the same (starting from 0 as EInt). So for example I have Node n1, n2, n3 and Edge e1, e2 (elements of an instance model) and their IDs were created from 0... as EInt so n1's ID is 0, n2's ID is 1 and e1's ID is 0 e2's ID is 1 but they are instances of different classes in the metamodel (class Node and class Edge). Is there any way to make the Diff/Merge distinguish them and separately detect the IDs per classes or should I make the IDs to be unique on the whole model (not only per classes)?
Re: How to use EMF Diff/Merge programmatically [message #1738426 is a reply to message #1738382] Tue, 19 July 2016 16:46 Go to previous message
Olivier Constant is currently offline Olivier ConstantFriend
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().
Previous Topic:How to compare two UML Model Resources ignoring XMI ids.
Next Topic:Undo and Redo operation in Diff/Merge
Goto Forum:
  


Current Time: Sat Dec 07 11:50:40 GMT 2024

Powered by FUDForum. Page generated in 0.04082 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top