Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMF Compare] Inverse use of EMF Compare(Try to find non-differencing elements)
[EMF Compare] Inverse use of EMF Compare [message #671231] Tue, 17 May 2011 08:28 Go to next message
Kai B. Heinz is currently offline Kai B. Heinz
Messages: 17
Registered: March 2011
Location: Germany
Junior Member
Hi,
I hope I got the right forum for an EMF Compare question. Otherwise please lead me to the right place, thanks.

I have two ecore models, where a lot of Elements are equal. Now I want to use EMF Compare to find these equal Elements. How can I do that? Certainly, I will find all differences, but how do I find "the rest"?

Thanks a lot,
Kai

[Updated on: Tue, 17 May 2011 08:29]

Report message to a moderator

Re: [EMF Compare] Inverse use of EMF Compare [message #671884 is a reply to message #671231] Thu, 19 May 2011 09:15 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Hi Kai,

We'd rather use the EMF newsgroup instead of EMFT (which is for incubating components).

As for your question : this isn't a use case that is planned for EMF Compare. You can achieve it programmaticaly though.

You will need to call both the match and diff engines :

MatchModel match = MatchService.doMatch(model1, model2);
DiffModel diff = DiffService.doDiff(match);

Then, you need to iterate through the match model's content and ignore the "unmatched" elements as well as the "matched" elements that have an associated DiffElement in the diff model. If your model elements are considered in a "Match2Element" instance of the match model, and they have no associated "DiffElement" instance, then they are considered "equal".

Laurent Goubet
Obeo
Re: [EMF Compare] Inverse use of EMF Compare [message #673635 is a reply to message #671884] Tue, 24 May 2011 09:57 Go to previous messageGo to next message
Kai B. Heinz is currently offline Kai B. Heinz
Messages: 17
Registered: March 2011
Location: Germany
Junior Member
Hi Laurent,
thanks a lot, that is a really nice solution and nearly solved my troubles.
Unfortunately I stick on the last step. I get a list of MatchElements from the MatchModel (precisly: matchModelObject.eContents().get(0).getSubMatchElements()) and on the other Hand a list of DiffElements from diffModelObject.getDifferences(). You wrote that MatchElements with no corresponding DiffElement considered to be equal. That sounds like a good idea, but how can I find which elements correspond with each other?
I constructed a double for-loop to compare every element from the first list with every element from the second one. The point where I compare them always return false by now, because I do not know how to compare a MatchModel object with a DiffModel object. Can you help me again?
Re: [EMF Compare] Inverse use of EMF Compare [message #675166 is a reply to message #673635] Mon, 30 May 2011 13:29 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Hi Kai,

If I remember correctly, there should be a "DiffGroup" instance for every object that has differences, thus you should be able to ignore all DiffElements that are not "DiffGroups". Then what you need to check is that "aDiffgroup.getRightParent()" is equal to "aMatch2Element.getRightElement()" (note : in some rare cases, the "DiffGroup.getRightParent()" will have a value from the _left_ model : we misnamed this reference, and it was too late when we realized it ... Though you should never encounter these : such a case should only happen for "DiffGroup" corresponding to "UnmatchedElement" instances). Unfortunately, the "DiffModel.getDifferences" method is meant for the "normal" use case of EMF Compare ... for which "DiffGroups" are of no importance. In terms of code, that would look like :

----------
List<MatchElement> matchElements = matchModelObject.eContents().get(0).getSubMatchElements();
List<DiffGroup> diffGroups = new ArrayList<DiffGroup>();
Iterator<DiffElement> iterator = diffModelObject.eAllContents();
while (iterator.hasNext()) {
DiffElement next = iterator.next();
if (next instanceof DiffGroup) {
diffGroups.add(next);
}
}

List<MatchElement> equalObjects = new ArrayList<MatchElement>(matchElements.size());
for (MatchElement match : matchElements) {
DiffGroup correspondingGroup = null;
for (DiffGroup group : diffGroups) {
if (((Match2Element)match).getRightElement() == group.getRightParent()) { // Note : not sure that instance equality is enough
correspondingGroup = group;
break;
}
}
if (correspondingGroup == null) {
equalObjects.add(match);
} else {
diffGroups.remove(correspondingGroup);
}
}
----------

Quick and dirty ... and not tested; but you get the idea Smile.

Laurent Goubet
Obeo
Re: [EMF Compare] Inverse use of EMF Compare [message #675334 is a reply to message #675166] Tue, 31 May 2011 08:08 Go to previous messageGo to next message
Kai B. Heinz is currently offline Kai B. Heinz
Messages: 17
Registered: March 2011
Location: Germany
Junior Member
Thanks a lot!
I had to make some minor changes to to code above, but now it works very well.
Kai
List<MatchElement> matchElements = 
		((MatchElement) matchModelObject.eContents().get(0)).getSubMatchElements();
List<DiffGroup> diffGroups = new ArrayList<DiffGroup>();
		
TreeIterator<EObject> iterator = diffObject.eAllContents();
while (iterator.hasNext()) 
{
	EObject next = iterator.next();
	if (next instanceof DiffGroup) 
	{
		diffGroups.add((DiffGroup)next);
	}
}
List<MatchElement> equalObjects = new ArrayList<MatchElement>(matchElements.size());
for (MatchElement match : matchElements) 
{
	DiffGroup correspondingGroup = null;
	for (DiffGroup group : diffGroups) 
	{
		if (((Match2Elements) match).getRightElement() == group.getRightParent()) 
		{ 
		// Note : not sure that instance equality is enough
			correspondingGroup = group;
			break;
		}
	}
			
	if (correspondingGroup == null) 
	{
		equalObjects.add(match);
	} 
	else 
	{
		diffGroups.remove(correspondingGroup);
	}
}

[Updated on: Wed, 13 July 2011 11:12]

Report message to a moderator

Re: [EMF Compare] Inverse use of EMF Compare [message #675362 is a reply to message #675334] Tue, 31 May 2011 09:27 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Kai,

Thanks for the feedback, that might be of interest to others Smile.

Laurent Goubet
Obeo
Previous Topic:[EMF Compare] opening editor programmatically results in unexpected/wrong view
Next Topic:Add png as an emf resource?
Goto Forum:
  


Current Time: Sat Oct 25 10:12:02 GMT 2014

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

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