Cannot merge added/deleted resources

If one of the comparison sides is empty (we're comparing only addition
or deletion of resources with no other resource existing on the
opposite side), EMF Compare is unable to merge the change because
there are no MatchResource allowing us to "find" the opposite
ResourceSet. This is a legacy of the early implementation in which
the comparison scope was no longer available once the comparison was
computed.

Change-Id: Ic1404c984dc651a2d70f53c1f628f673efe629d5
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ResourceAttachmentChangeMerger.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ResourceAttachmentChangeMerger.java
index 9984bfa..5066828 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ResourceAttachmentChangeMerger.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ResourceAttachmentChangeMerger.java
@@ -18,6 +18,7 @@
 import java.util.List;
 
 import org.apache.log4j.Logger;
+import org.eclipse.emf.common.notify.Notifier;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.compare.Comparison;
 import org.eclipse.emf.compare.Diff;
@@ -27,10 +28,12 @@
 import org.eclipse.emf.compare.MatchResource;
 import org.eclipse.emf.compare.ResourceAttachmentChange;
 import org.eclipse.emf.compare.internal.utils.DiffUtil;
+import org.eclipse.emf.compare.scope.IComparisonScope;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.InternalEObject;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.emf.ecore.xmi.XMIResource;
 
 /**
@@ -354,15 +357,32 @@
 						+ sourceRes.getURI());
 			}
 
-			final List<MatchResource> matchedResources = comparison.getMatchedResources();
-			final int size = matchedResources.size();
 			ResourceSet targetSet = null;
-			for (int i = 0; i < size && targetSet == null; i++) {
-				final MatchResource matchRes = matchedResources.get(i);
-				if (rightToLeft && matchRes.getLeft() != null) {
-					targetSet = matchRes.getLeft().getResourceSet();
-				} else if (!rightToLeft && matchRes.getRight() != null) {
-					targetSet = matchRes.getRight().getResourceSet();
+			IComparisonScope scope = (IComparisonScope)EcoreUtil.getAdapter(comparison.eAdapters(),
+					IComparisonScope.class);
+			if (rightToLeft) {
+				Notifier left = scope.getLeft();
+				if (left instanceof ResourceSet) {
+					targetSet = (ResourceSet)left;
+				} else if (left instanceof Resource) {
+					targetSet = ((Resource)left).getResourceSet();
+				} else if (left instanceof EObject) {
+					Resource res = ((EObject)left).eResource();
+					if (res != null) {
+						targetSet = res.getResourceSet();
+					}
+				}
+			} else {
+				Notifier right = scope.getRight();
+				if (right instanceof ResourceSet) {
+					targetSet = (ResourceSet)right;
+				} else if (right instanceof Resource) {
+					targetSet = ((Resource)right).getResourceSet();
+				} else if (right instanceof EObject) {
+					Resource res = ((EObject)right).eResource();
+					if (res != null) {
+						targetSet = res.getResourceSet();
+					}
 				}
 			}