@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Reference reAttach(IdEObject mainObject) { // System.out.println("Re-attaching M " + getReferredObject() + " to " + mainObject + " on " + getIdEObject() + "." + geteReference().getName()); AbstractEList list = (AbstractEList) getIdEObject().eGet(geteReference()); int index = list.indexOf(getReferredObject()); if (index != -1) { try { list.set(index, mainObject); } catch (IllegalArgumentException e) { // e.printStackTrace(); } } // TODO if the old object really does exist multiple times, the new object should also exist multiple times... but it's probably a bug that it's there multiple times in the first place... while (list.contains(getReferredObject())) { list.remove(getReferredObject()); } return new MultiReference(getIdEObject(), mainObject, geteReference()); } }