Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to extend EcoreUtil.Copier to copy EOpposite references(Copying EOpposite references with EcoreUtil.Copier)
How to extend EcoreUtil.Copier to copy EOpposite references [message #1802183] Sun, 03 February 2019 07:58
Pablo Gomez Abajo is currently offline Pablo Gomez AbajoFriend
Messages: 8
Registered: February 2019
Junior Member
I'm trying to extend EcoreUtil.Copier class to copy EOpposite references as well, but I'm not getting to the right solution yet. How can I proceed?

This is my code for the EcoreUtil.Copier.copyReference method, still not working:

@Override
	protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject)
	{
		if (eObject.eIsSet(eReference))
		{
			EStructuralFeature.Setting setting = getTarget(eReference, eObject, copyEObject);
			if (setting != null)
			{
				Object value = eObject.eGet(eReference, resolveProxies);
				if (eReference.isMany())
				{
					@SuppressWarnings("unchecked") InternalEList<EObject> source = (InternalEList<EObject>)value;
					@SuppressWarnings("unchecked") InternalEList<EObject> target = (InternalEList<EObject>)setting;
					if (source.isEmpty())
					{
						target.clear();
					}
					else
					{
						boolean isBidirectional = eReference.getEOpposite() != null && !eReference.getEOpposite().isMany();
						int index = 0;
						for (Iterator<EObject> k = resolveProxies ? source.iterator() : source.basicIterator(); k.hasNext();)
						{
							EObject referencedEObject = k.next();
							EObject copyReferencedEObject = get(referencedEObject);
							if (copyReferencedEObject == null)
							{
								if (useOriginalReferences && !isBidirectional)
								{
									target.addUnique(index, referencedEObject);
									++index;
								}
							}
							else
							{
								if (isBidirectional)
								{
									int position = target.indexOf(copyReferencedEObject);
									if (position == -1)
									{
										target.addUnique(index, copyReferencedEObject);
									}
									else if (index != position)
									{
										target.move(index, copyReferencedEObject);
									}
								}
								else
								{
									target.addUnique(index, copyReferencedEObject);
								}
								++index;
							}
						}
					}
				}
				else
				{
					if (value == null)
					{
						setting.set(null);
					}
					else
					{
						Object copyReferencedEObject = get(value);
						if (copyReferencedEObject == null)
						{
							if (useOriginalReferences && !(eReference.getEOpposite() != null && !eReference.getEOpposite().isMany()))
							{
								setting.set(value);
							}
						}
						else
						{
							setting.set(copyReferencedEObject);
						}
					}
				}
			}
		}
	}


Many thanks and regards,

Pablo

Previous Topic:Are static JET templates useable?
Next Topic:Resource /library.editor does not exist
Goto Forum:
  


Current Time: Sun Aug 25 04:28:53 GMT 2019

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

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

Back to the top