eclipse-sirius / sirius-emf-json

JSON-based EMF Resource implementation - part of Eclipse Sirius
https://eclipse.dev/sirius/sirius-web.html
Eclipse Public License 2.0
5 stars 10 forks source link

[41] Use EMF's intrinsicIDToEObjectMap if present #47

Closed pcdavid closed 1 week ago

pcdavid commented 1 week ago

The previous commit (1f4402943) completely disabled EMF's default getEObjectByID in favor of using our own JSONResourceImpl-specific id map. However there are cases where we still want to lookup elements by their intrinsic (modeled) id instead of the IDManager-provided one, without incurring the cost of an eAllContents() on failure.

This change allows for this to work, as long as the JSONResourceImpl has been setup with a non-null intrinsicIDToEObjectMap. For example right after the resource creation:

((ResourceImpl) resource).setIntrinsicIDToEObjectMap(new HashMap<>());

Once this is done, any new object added to the resource will get its intrinsic id cached in this map (see ResourceImpl.attachedHelper()) and JsonResourceImpl.getEObjectById will find it there (if present) while still bypassing the whole eAllContents() search in super.getEObjectByID(id).

Bug: https://github.com/eclipse-sirius/sirius-emf-json/issues/41