From 393167d8bda985f46c8378c854d8dcb3c01a8da2 Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Tue, 6 Mar 2018 14:48:30 +0000
Subject: [PATCH] - Add replaceEObjectReferences() refs 3219

---
 .../org/fortiss/tooling/kernel/utils/.ratings  |  2 +-
 .../tooling/kernel/utils/EcoreUtils.java       | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/.ratings b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/.ratings
index 66e2d2e17..d9c687d08 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/.ratings
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/.ratings
@@ -2,7 +2,7 @@ CompositionUtils.java a2b1c7f4b1ae4d0783b4e170e432a9e02fc451fd GREEN
 ConstraintsUtils.java 93ae55d9c4a2645a97bb4162f43eb00acbc94633 GREEN
 EMFResourceUtils.java 01cddc68d7dd199191792d87f8256d6c52540856 GREEN
 EcoreSerializerBase.java 63b879cb32a0981dc1fefaf33db098abe81fe520 GREEN
-EcoreUtils.java 008f4743d5092afb13c7f4cbbfcb83f1dc6b7721 GREEN
+EcoreUtils.java c191385af86ff630d1ad9daacb42751527db8744 YELLOW
 ExtensionPointUtils.java e3ec0d396b0a88c040fd0117d4a369340d6099f4 GREEN
 IdentifierUtils.java d074a0f40d0ace7c2dd4ec145f0c2d783fbe115d GREEN
 JavaUtils.java 88bebee35226100989e118b272c766fa63f3c87c GREEN
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java
index 94c90d21a..304f2d582 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java
@@ -18,6 +18,7 @@ package org.fortiss.tooling.kernel.utils;
 import static org.eclipse.emf.common.notify.Notification.EVENT_TYPE_COUNT;
 import static org.eclipse.emf.ecore.util.EcoreUtil.getAllContents;
 import static org.eclipse.emf.ecore.util.EcoreUtil.getRootContainer;
+import static org.eclipse.emf.ecore.util.EcoreUtil.replace;
 import static org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer.find;
 
 import java.util.Collection;
@@ -43,6 +44,7 @@ import org.eclipse.emf.ecore.EPackage;
 import org.eclipse.emf.ecore.EPackage.Registry;
 import org.eclipse.emf.ecore.EReference;
 import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.resource.ResourceSet;
 import org.eclipse.emf.ecore.util.EcoreUtil;
@@ -495,6 +497,22 @@ public class EcoreUtils {
 		return usages;
 	}
 
+	/**
+	 * Replaces all references to the {@link EObject}s contained in the key set of the given
+	 * {@code objectMap} with the corresponding elements they are mapped to.
+	 * 
+	 * @param eObjectMap
+	 *            Maps each old {@link EObject} to the corresponding new {@link EObject}
+	 */
+	public static void
+			replaceEObjectReferences(Map<? extends EObject, ? extends EObject> eObjectMap) {
+		for(EObject eObject : eObjectMap.keySet()) {
+			for(Setting setting : getAllReferences(eObject)) {
+				replace(setting, eObject, eObjectMap.get(eObject));
+			}
+		}
+	}
+
 	/**
 	 * <p>
 	 * Disables the notifications emitted by the given {@link EObject} and its children.
-- 
GitLab