From df41d5b2498993e6541dffa1d20638dfb57a1fc5 Mon Sep 17 00:00:00 2001 From: Simon Haug Date: Mon, 25 Sep 2023 09:20:58 +0200 Subject: [PATCH] Make getUuidForReadOnlyEObject() independet of xmi-ids instead of EcoreUtil.getURI (which may depend on instance specific xmi-ids) use ObjectResolutionUtil.getHierarchicUriFragment (not using xmi-ids) in some cases --- .../change/atomic/uuid/UuidResolverImpl.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bundles/tools.vitruv.change.atomic/src/tools/vitruv/change/atomic/uuid/UuidResolverImpl.java b/bundles/tools.vitruv.change.atomic/src/tools/vitruv/change/atomic/uuid/UuidResolverImpl.java index 7b95c315..0a5ed5ed 100644 --- a/bundles/tools.vitruv.change.atomic/src/tools/vitruv/change/atomic/uuid/UuidResolverImpl.java +++ b/bundles/tools.vitruv.change.atomic/src/tools/vitruv/change/atomic/uuid/UuidResolverImpl.java @@ -17,6 +17,7 @@ import org.apache.log4j.Logger; import org.eclipse.emf.common.util.URI; 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; @@ -25,6 +26,7 @@ import com.google.common.collect.HashBiMap; import tools.vitruv.change.atomic.hid.HierarchicalId; +import tools.vitruv.change.atomic.hid.ObjectResolutionUtil; import tools.vitruv.change.atomic.hid.internal.HierarchicalIdResolver; class UuidResolverImpl implements UuidResolver { @@ -79,12 +81,13 @@ public void registerEObject(Uuid uuid, EObject eObject) throws IllegalStateExcep } eObjectToUuid.put(eObject, uuid); } - + @Override public void unregisterEObject(Uuid uuid, EObject eObject) throws IllegalStateException { checkState(uuid != null, "uuid must not be null"); checkState(eObject != null, "object must not be null"); - checkState(uuid.equals(eObjectToUuid.get(eObject)), "trying to unregister element %s but is not registered for uuid %s", eObject, uuid); + checkState(uuid.equals(eObjectToUuid.get(eObject)), + "trying to unregister element %s but is not registered for uuid %s", eObject, uuid); eObjectToUuid.remove(eObject); } @@ -108,7 +111,8 @@ public void endTransaction() { while (iterator.hasNext()) { EObject object = iterator.next(); checkState(object.eResource() != null, "dangling object %s detected", object); - checkState(object.eResource().getResourceSet() == resourceSet, "object %s is contained in wrong resource set", object); + checkState(object.eResource().getResourceSet() == resourceSet, + "object %s is contained in wrong resource set", object); } } @@ -177,6 +181,16 @@ private Uuid getUuidOrNull(EObject eObject) { } private Uuid getUuidForReadOnlyEObject(EObject eObject) { + URI proxyURI = ((InternalEObject) eObject).eProxyURI(); + Resource resource = eObject.eResource(); + + if (proxyURI == null && resource != null) { + URI uri = resource.getURI(); + String uriFragment = ObjectResolutionUtil.getHierarchicUriFragment(eObject); + uri = uri == null ? URI.createURI("#" + uriFragment) : uri.appendFragment(uriFragment); + return new Uuid(uri.toString()); + } + return new Uuid(EcoreUtil.getURI(eObject).toString()); }