Skip to content
Snippets Groups Projects
Commit a795e081 authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

fix attempt via a gross ugly hack. See EcoreUtils.copy

refs 2049
parent af825495
No related branches found
No related tags found
No related merge requests found
......@@ -24,12 +24,15 @@ import java.util.List;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.NotificationImpl;
import org.eclipse.emf.common.util.AbstractEList;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
/**
* Utility methods for dealing with .ecore models. These methods should be used
......@@ -38,7 +41,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: AC63FE26BD51D0F6080CC6D0AD2508E3
* @ConQAT.Rating YELLOW Hash: 1B2A42365F56FD17DA8B4C77AD1793C7
*/
public class EcoreUtils {
......@@ -54,6 +57,7 @@ public class EcoreUtils {
/**
* Converts an EList of a given type into an EList of one of its subtypes.
* Utility method to avoid unnecessary casts.
* FIXME(VA) Redundant with JavaUtils.convertList
*
* @param targetClass
* - the class representing the subtype
......@@ -217,4 +221,50 @@ public class EcoreUtils {
public static void postRefreshNotification(EObject eObject) {
eObject.eNotify(refreshNotification);
}
/**
* Hack to the EcoreUtils copier which removes some duplicates in some lists, whereas we DO NOT
* want it.
*/
private static class HackedCopier extends EcoreUtil.Copier {
/** {@inheritDoc} */
@Override
protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) {
if(eObject.eIsSet(eReference)) {
if(eReference.isMany()) {
@SuppressWarnings("unchecked") List<EObject> source =
(List<EObject>)eObject.eGet(eReference);
@SuppressWarnings("unchecked") AbstractEList<EObject> target =
(AbstractEList<EObject>)copyEObject.eGet(getTarget(eReference));
if(source.isEmpty()) {
target.clear();
} else {
// Here is the hack: we use addAllUnique instead of addAll!
target.addAllUnique(copyAll(source));
}
} else {
EObject childEObject = (EObject)eObject.eGet(eReference);
copyEObject.eSet(getTarget(eReference), childEObject == null ? null
: copy(childEObject));
}
}
}
}
/**
* Returns a self-contained copy of the eObject.
*
* @param eObject
* the object to copy.
* @return the copy.
* @see Copier
*/
public static <T extends EObject> T copy(T eObject) {
Copier copier = new HackedCopier();
EObject result = copier.copy(eObject);
copier.copyReferences();
@SuppressWarnings("unchecked") T t = (T)result;
return t;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment