[579051] Use the global Orphanage when shared
diff --git a/examples/org.eclipse.ocl.examples.codegen/src/org/eclipse/ocl/examples/codegen/analyzer/AS2CGVisitor.java b/examples/org.eclipse.ocl.examples.codegen/src/org/eclipse/ocl/examples/codegen/analyzer/AS2CGVisitor.java
index c67b239..8a8add2 100644
--- a/examples/org.eclipse.ocl.examples.codegen/src/org/eclipse/ocl/examples/codegen/analyzer/AS2CGVisitor.java
+++ b/examples/org.eclipse.ocl.examples.codegen/src/org/eclipse/ocl/examples/codegen/analyzer/AS2CGVisitor.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013, 2021 CEA LIST and others.
+ * Copyright (c) 2013, 2022 CEA LIST and others.
  * All rights reserved.   This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/CompleteEnvironmentImpl.java b/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/CompleteEnvironmentImpl.java
index d8048f4..3452bef 100644
--- a/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/CompleteEnvironmentImpl.java
+++ b/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/CompleteEnvironmentImpl.java
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2010, 2019 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/CompleteModelImpl.java b/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/CompleteModelImpl.java
index ef43ab9..446e42d 100644
--- a/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/CompleteModelImpl.java
+++ b/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/CompleteModelImpl.java
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2010, 2019 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -595,7 +595,7 @@
 	public @NonNull Orphanage getOrphanage() {
 		Orphanage orphanage2 = orphanage;
 		if (orphanage2 == null) {
-			orphanage2 = orphanage = environmentFactory.getMetamodelManager().createOrphanage();
+			orphanage2 = orphanage = Orphanage.getOrphanage();
 			orphanage2.addPackageListener(getOrphanCompletePackage().getPartialPackages());
 		}
 		return orphanage2;
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/complete/CompleteClasses.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/complete/CompleteClasses.java
index c9af3e9..85af337 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/complete/CompleteClasses.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/complete/CompleteClasses.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2019 Willink Transformations and others.
+ * Copyright (c) 2014, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -37,7 +37,6 @@
 import org.eclipse.ocl.pivot.internal.CompleteClassImpl;
 import org.eclipse.ocl.pivot.internal.CompletePackageImpl;
 import org.eclipse.ocl.pivot.internal.manager.Orphanage;
-import org.eclipse.ocl.pivot.internal.manager.PivotMetamodelManager;
 import org.eclipse.ocl.pivot.util.PivotPlugin;
 import org.eclipse.ocl.pivot.utilities.ClassUtil;
 import org.eclipse.ocl.pivot.utilities.PivotConstants;
@@ -99,8 +98,7 @@
 				logger.error("Out of range upper bound", e);
 			}
 			specializedType.setUnspecializedElement(unspecializedType);
-			PivotMetamodelManager metamodelManager = getCompleteModel().getMetamodelManager();
-			Orphanage orphanage = Orphanage.getOrphanage(metamodelManager.getASResourceSet());
+			Orphanage orphanage = Orphanage.getOrphanage();
 			specializedType.setOwningPackage(orphanage);
 			return specializedType;
 		}
@@ -198,8 +196,7 @@
 			specializedMapType.setKeysAreNullFree(typeParameters.isKeysAreNullFree());
 			specializedMapType.setValuesAreNullFree(typeParameters.isValuesAreNullFree());
 			specializedMapType.setUnspecializedElement(unspecializedType);
-			PivotMetamodelManager metamodelManager = getCompleteModel().getMetamodelManager();
-			Orphanage orphanage = Orphanage.getOrphanage(metamodelManager.getASResourceSet());
+			Orphanage orphanage = Orphanage.getOrphanage();
 			specializedMapType.setOwningPackage(orphanage);
 			specializedMapType.setEntryClass(typeParameters.getEntryClass());
 			return specializedMapType;
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/complete/PartialClasses.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/complete/PartialClasses.java
index 4ce9cac..9aafb64 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/complete/PartialClasses.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/complete/PartialClasses.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2019 Willink Transformations and others.
+ * Copyright (c) 2014, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -242,8 +242,7 @@
 //			specializedMetaclass.setInstanceType(instanceType);
 //		}
 		specializedType.setUnspecializedElement(unspecializedType);
-		PivotMetamodelManager metamodelManager = getCompleteModel().getMetamodelManager();
-		Orphanage orphanage = Orphanage.getOrphanage(metamodelManager.getASResourceSet());
+		Orphanage orphanage = Orphanage.getOrphanage();
 		specializedType.setOwningPackage(orphanage);
 		return specializedType;
 	}
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java
index 17762c6..1bcd75c 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2021 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/Orphanage.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/Orphanage.java
index 9834371..f4cd44e 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/Orphanage.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/Orphanage.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2021 Willink Transformations and others.
+ * Copyright (c) 2011, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -37,6 +37,7 @@
 import org.eclipse.ocl.pivot.internal.resource.ASResourceImpl;
 import org.eclipse.ocl.pivot.internal.resource.OCLASResourceFactory;
 import org.eclipse.ocl.pivot.internal.utilities.PivotConstantsInternal;
+import org.eclipse.ocl.pivot.internal.utilities.PivotUtilInternal;
 import org.eclipse.ocl.pivot.utilities.ClassUtil;
 import org.eclipse.ocl.pivot.utilities.PivotConstants;
 
@@ -47,11 +48,21 @@
  */
 public class Orphanage extends PackageImpl
 {
+	/**
+	 * The OrphanResource tailors the inherited ASREsorce functionality to support the single Resource shared by all
+	 * OCL consumers, but not included in any REsourceSEt. It is nt saved and hso has no xmi:ids but it does have LUSSIDs
+	 * in order to contribute to the signatures of operations.
+	 */
 	protected static class OrphanResource extends ASResourceImpl
 	{
 		protected OrphanResource(@NonNull URI uri) {
 			super(uri, OCLASResourceFactory.getInstance());
-			setSaveable(false);
+			setUpdating(true);
+		}
+
+		@Override
+		public NotificationChain basicSetResourceSet(ResourceSet resourceSet, NotificationChain notifications) {
+			return notifications; 	// The OrphanResource is in no, rather than latest, ResourceSt
 		}
 
 		@Override
@@ -68,6 +79,18 @@
 		}
 
 		@Override
+		public String getURIFragment(EObject eObject) {
+			// The OrphanResource cannot be saved so has no LUSSID-based xmi:ids, but Xtext serialization needs a URI
+			return superGetURIFragment(eObject);
+		}
+
+		@Override
+		public ResourceSet getResourceSet() {
+			// OrphanResource can be shared across many ResourceSets - use the current one
+			return PivotUtilInternal.getEnvironmentFactory(null).getMetamodelManager().getASResourceSet();
+		}
+
+		@Override
 		public boolean isOrphanage() {
 			return true;
 		}
@@ -89,11 +112,11 @@
 		 */
 		protected static class ListIterator<T> implements java.util.ListIterator<T>
 		{
-			protected final @NonNull List<Map.Entry<T,Integer>> list;
+			protected final @NonNull List<Map.@NonNull Entry<@NonNull T, @NonNull Integer>> list;
 			private final int size;
 			private int cursor;
 
-			public ListIterator(@NonNull List<Map.Entry<T,Integer>> list, int index) {
+			public ListIterator(@NonNull List<Map.@NonNull Entry<@NonNull T, @NonNull Integer>> list, int index) {
 				this.list = list;
 				this.size = list.size();
 				this.cursor = index;
@@ -159,7 +182,7 @@
 		/**
 		 * Map of content-value to list-index.
 		 */
-		private final @NonNull WeakHashMap<T, Integer> weakMap = new WeakHashMap<T, Integer>();
+		private final @NonNull WeakHashMap<@NonNull T, @NonNull Integer> weakMap = new WeakHashMap<>();
 
 		/**
 		 * Incrermenting counter used to sort the list into a predictable order.
@@ -169,7 +192,7 @@
 		/**
 		 * The most recent ordered view of the weakMap.
 		 */
-		private @Nullable List<Entry<T, Integer>> weakList = null;
+		private @Nullable List<@NonNull Entry<@NonNull T, @NonNull Integer>> weakList = null;
 
 		@Override
 		public boolean addAllUnique(Object[] objects, int start, int end) {
@@ -203,6 +226,7 @@
 
 		@Override
 		public NotificationChain basicAdd(T object, NotificationChain notifications) {
+			assert object != null;
 			synchronized (weakMap) {
 				if (!weakMap.containsKey(object)) {
 					weakMap.put(object, Integer.valueOf(counter++));
@@ -281,16 +305,16 @@
 
 		@Override
 		public T get(int index) {
-			List<Entry<T, Integer>> weakList2 = getList();
+			List<@NonNull Entry<@NonNull T, @NonNull Integer>> weakList2 = getList();
 			return weakList2.get(index).getKey();
 		}
 
-		private @NonNull List<Entry<T, Integer>> getList() {
-			List<Entry<T, Integer>> weakList2;
+		private @NonNull List<@NonNull Entry<@NonNull T, @NonNull Integer>> getList() {
+			List<@NonNull Entry<@NonNull T, @NonNull Integer>> weakList2;
 			synchronized (weakMap) {
 				weakList2 = weakList;
 				if (weakList2 == null) {
-					weakList2 = weakList = new ArrayList<Entry<T, Integer>>(weakMap.entrySet());
+					weakList2 = weakList = new ArrayList<>(weakMap.entrySet());
 					Collections.sort(weakList2, new Comparator<Entry<T, Integer>>()
 					{
 						@Override
@@ -365,12 +389,14 @@
 	}
 
 	public static final @NonNull URI ORPHANAGE_URI = ClassUtil.nonNullEMF(URI.createURI(PivotConstants.ORPHANAGE_URI + PivotConstants.DOT_OCL_AS_FILE_EXTENSION));
-	private static Orphanage INSTANCE = null;
+	private static Orphanage ORPHAN_PACKAGE = null;
+	private static OrphanResource ORPHAN_RESOURCE = null;
 
 	public static void disposeInstance() {
-		if (INSTANCE != null) {
-			INSTANCE.dispose();
-			INSTANCE = null;
+		if (ORPHAN_PACKAGE != null) {
+			ORPHAN_PACKAGE.dispose();
+			ORPHAN_PACKAGE = null;
+			ORPHAN_RESOURCE = null;
 		}
 	}
 
@@ -378,6 +404,7 @@
 	 * Return the Orphanage for an eObject, which is the Orphanage resource in the same ResourceSet as
 	 * the eObject, else the global Orphanage.
 	 */
+	@Deprecated /* @deprecated Not used, the global orphanage should always be used - See Bug 579051 */
 	public static @Nullable Orphanage getOrphanage(@NonNull EObject eObject) {
 		//		if (eObject == null) {
 		//			return null;
@@ -391,37 +418,46 @@
 	}
 
 	/**
-	 * Return the Orphanage for an eObject, which is the Orphanage resource in the resourceSet
-	 * if non-null, else the global Orphanage.
+	 * Return the global Orphanage.
 	 */
-	public static @NonNull Orphanage getOrphanage(@Nullable ResourceSet resourceSet) {
-		if (resourceSet == null) {
-			Orphanage instance2 = INSTANCE;
-			if (instance2 == null) {
-				instance2 = INSTANCE = new Orphanage(PivotConstants.ORPHANAGE_NAME, PivotConstants.ORPHANAGE_URI);
-			}
-			return instance2;
+	public static @NonNull Orphanage getOrphanage() {
+		OrphanResource orphanResource = ORPHAN_RESOURCE;
+		Orphanage orphanPackage = ORPHAN_PACKAGE;
+		if (orphanPackage == null) {
+			orphanPackage = ORPHAN_PACKAGE = new Orphanage(PivotConstants.ORPHANAGE_NAME, PivotConstants.ORPHANAGE_URI);
+			Model orphanModel = PivotFactory.eINSTANCE.createModel();
+			orphanModel.setName(PivotConstants.ORPHANAGE_NAME);;
+			orphanModel.setExternalURI(PivotConstants.ORPHANAGE_URI);
+			orphanModel.getOwnedPackages().add(orphanPackage);
+			orphanResource = ORPHAN_RESOURCE = new OrphanResource(ORPHANAGE_URI);
+			orphanResource.getContents().add(orphanModel);
+			orphanResource.setSaveable(false);
 		}
-		for (Resource aResource : resourceSet.getResources()) {
-			for (EObject eContent : aResource.getContents()) {
-				if (eContent instanceof Model) {
-					for (org.eclipse.ocl.pivot.Package asPackage : ((Model)eContent).getOwnedPackages()) {
-						if (asPackage instanceof Orphanage) {
-							return (Orphanage) asPackage;
-						}
-					}
-				}
+		return orphanPackage;
+	}
+
+	/**
+	 * Return the Orphanage for resourceSet.
+	 * The global orphanage contains the globally unique shared orphan,
+	 * A local orphanage holds the subset of the overall orphans necessary to support serialization.
+	 */
+	@Deprecated /* @deprecated - not used - use the shared global Prphange */
+	public static @NonNull Orphanage getOrphanage(@NonNull ResourceSet resourceSet) {
+		if (ORPHAN_PACKAGE == null) {
+			return getOrphanage();
+		}
+		Orphanage orphanPackage = ORPHAN_PACKAGE;
+		OrphanResource orphanResource = ORPHAN_RESOURCE;
+		assert orphanPackage != null;
+		assert orphanResource != null;
+		EList<@NonNull Resource> resources = resourceSet.getResources();
+		for (Resource aResource : resources) {
+			if (aResource == orphanResource) {
+				return orphanPackage;
 			}
 		}
-		Orphanage orphanage = new Orphanage(PivotConstants.ORPHANAGE_NAME, PivotConstants.ORPHANAGE_URI);
-		Model orphanModel = PivotFactory.eINSTANCE.createModel();
-		orphanModel.setName(PivotConstants.ORPHANAGE_NAME);;
-		orphanModel.setExternalURI(PivotConstants.ORPHANAGE_URI);
-		orphanModel.getOwnedPackages().add(orphanage);
-		Resource orphanageResource = new OrphanResource(ORPHANAGE_URI);
-		orphanageResource.getContents().add(orphanModel);
-		resourceSet.getResources().add(orphanageResource);
-		return orphanage;
+		resources.add(orphanResource);
+		return orphanPackage;
 	}
 
 	/**
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/PivotMetamodelManager.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/PivotMetamodelManager.java
index 14e28fc..66a0dbf 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/PivotMetamodelManager.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/manager/PivotMetamodelManager.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2021 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -591,6 +591,7 @@
 		}
 	}
 
+	@Deprecated /* @deprecated - not used - use the shared global Prphange */
 	public @NonNull Orphanage createOrphanage() {
 		return Orphanage.getOrphanage(asResourceSet);
 	}
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/AS2ID.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/AS2ID.java
index b322c45..c01b18a 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/AS2ID.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/AS2ID.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2017, 2019 Willink Transformations and others.
+ * Copyright (c) 2017, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/ASResourceImpl.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/ASResourceImpl.java
index 1704a4e..1b922f2 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/ASResourceImpl.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/ASResourceImpl.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2020 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved.   This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -197,6 +197,13 @@
 		return notificationChain;
 	}
 
+	/**
+	 * @since 1.18
+	 */
+	protected @NonNull ImmutabilityCheckingAdapter createImmutabilityCheckingAdapter() {
+		return new ImmutabilityCheckingAdapter();
+	}
+
 	@Override
 	protected XMLSave createXMLSave() {
 		return new PivotSaveImpl(new XMIHelperImpl(this)
@@ -432,6 +439,13 @@
 		}
 	}
 
+	/**
+	 * @since 1.18
+	 */
+	protected String superGetURIFragment(EObject eObject) {
+		return super.getURIFragment(eObject);		// Bypass assignIds for use by OrphanResource
+	}
+
 	@Override
 	protected void unloaded(InternalEObject internalEObject) {
 		if (internalEObject instanceof PivotObjectImpl) {
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/LUSSIDs.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/LUSSIDs.java
index 70583bf..c4150b4 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/LUSSIDs.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/resource/LUSSIDs.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2017, 2018 Willink Transformations and others.
+ * Copyright (c) 2017, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -33,14 +33,14 @@
 
 /**
  * The LUSSIDs class maintains the element to LUSSID and LUSSID to element mapping for the elements
- * of an ASResource. It also privides the ability to return predictable xmi:id values.
+ * of an ASResource. It also provides the ability to return predictable xmi:id values.
  *
  * An xmi:id is provided for every explicitly referenced, and every potentially externally referenced element,
- * so that the EMF fall-back to @x/@y.1 style id referemces is never required.
+ * so that the EMF fall-back to @x/@y.1 style id references is never required.
  *
  * The xmi:id typically comprises a 5 Base64-like letter encoding of the bottom 30 bits of the LUSSID of the element.
  * Additional Base64 letters are occasionally needed to disambiguate duplicates. Disambiguation favours the externally
- * referenceable xmi:ids before falling back on hierachical position. Disambiguation is therefore very likley to give
+ * referenceable xmi:ids before falling back on hierachical position. Disambiguation is therefore very likely to give
  * stable results after many forms of model evolution.
  *
  * The LUSSID (Locally Unique Semantically Sentsitive ID) is the hashcode of the hierarchical path of the element.
@@ -419,6 +419,7 @@
 	}
 
 	protected void assignXMIIDs(@NonNull AS2ID as2id) {
+		assert !asResource.isOrphanage();
 		Map<@NonNull String, @NonNull List<@NonNull Element>> xmiid2collisions2 = xmiid2collisions;
 		for (@NonNull Element element : identifiedElement2lussid.keySet()) {
 			Integer lussid = identifiedElement2lussid.get(element);
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/resource/ASResource.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/resource/ASResource.java
index 9fda570..cab9662 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/resource/ASResource.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/resource/ASResource.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2018 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved.   This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -99,7 +99,7 @@
 	 *
 	 * @since 1.5
 	 */
-	public @NonNull LUSSIDs getLUSSIDs(@NonNull Map<@NonNull Object, @Nullable Object> options);
+	 @NonNull LUSSIDs getLUSSIDs(@NonNull Map<@NonNull Object, @Nullable Object> options);
 
 	/**
 	 * Return the Model that provides the sole root content. Throws an IllegalStateException if there is none.
@@ -111,7 +111,7 @@
 	 *
 	 * @since 1.5
 	 */
-	public int getXmiidVersion();
+	 int getXmiidVersion();
 
 	/**
 	 * Return true if this Resource is a container for orphan model elements.
@@ -134,7 +134,7 @@
 	 *
 	 * @since 1.5
 	 */
-	public void resetLUSSIDs();
+	void resetLUSSIDs();
 
 	/**
 	 * Enable or disable saving of this resource. Saving is normally disabled automatically for model content
@@ -144,12 +144,12 @@
 	 *
 	 * @since 1.5
 	 */
-	public void setSaveable(boolean isSaveable);
+	void setSaveable(boolean isSaveable);
 
 	/**
 	 * Define the version number identifying the xmi:id allocation algorithm for this resource.
 	 *
 	 * @since 1.5
 	 */
-	public void setXmiidVersion(int xmiidVersion);
+	void setXmiidVersion(int xmiidVersion);
 }
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/PivotUtil.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/PivotUtil.java
index e8d578c..bd89f76 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/PivotUtil.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/PivotUtil.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2021 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/as2cs/AS2CSConversion.java b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/as2cs/AS2CSConversion.java
index 2d5ff93..347e461 100644
--- a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/as2cs/AS2CSConversion.java
+++ b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/as2cs/AS2CSConversion.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2019 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2AS.java b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2AS.java
index 6bcc99a..e039e90 100644
--- a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2AS.java
+++ b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2AS.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2019 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2ASConversion.java b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2ASConversion.java
index 970086f..809c091 100644
--- a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2ASConversion.java
+++ b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2ASConversion.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2020 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -339,7 +339,6 @@
 		}
 		allPivotResources.addAll(metamodelManager.getLibraries());			// Library elements are not dead
 		allPivotResources.addAll(cs2asResourceMap.keySet());			// Incoming elements are not dead
-		allPivotResources.remove(metamodelManager.getCompleteModel().getOrphanage().eResource());
 		@SuppressWarnings("serial")
 		Map<EObject, Collection<Setting>> referencesToOrphans = new EcoreUtil.CrossReferencer(allPivotResources)
 		{
diff --git a/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/attributes/AbstractOperationMatcher.java b/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/attributes/AbstractOperationMatcher.java
index 65632cd..7ef5d45 100644
--- a/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/attributes/AbstractOperationMatcher.java
+++ b/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/attributes/AbstractOperationMatcher.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2018 Willink Transformations and others.
+ * Copyright (c) 2011, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/cs2as/EssentialOCLCSLeft2RightVisitor.java b/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/cs2as/EssentialOCLCSLeft2RightVisitor.java
index cc5d7e5..9bc5c10 100644
--- a/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/cs2as/EssentialOCLCSLeft2RightVisitor.java
+++ b/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/cs2as/EssentialOCLCSLeft2RightVisitor.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2019 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/PivotTestCase.java b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/PivotTestCase.java
index 0690889..ed67d05 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/PivotTestCase.java
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/PivotTestCase.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2021 Willink Transformations and others.
+ * Copyright (c) 2011, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/LoadTests.java b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/LoadTests.java
index 2fd0af8..3febb92 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/LoadTests.java
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/LoadTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2021 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -1208,7 +1208,7 @@
 
 	public void testLoad_Fruit_ocl() throws IOException, InterruptedException {
 		UMLStandaloneSetup.init();
-		OCL ocl = createOCL();
+		OCL ocl = createOCLWithProjectMap();
 		UMLPackage.eINSTANCE.getClass();
 		doLoad(ocl, getTestModelURI("models/uml/Fruit.ocl"));
 		ocl.dispose();
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/MonikerTests.java b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/MonikerTests.java
index b4b57a5..1314531 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/MonikerTests.java
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/MonikerTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2018 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/PivotTests.java b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/PivotTests.java
index e7435a7..ab25dbb 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/PivotTests.java
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/PivotTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2021 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/RoundTripTests.java b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/RoundTripTests.java
index ab4c2f9..37a9e29 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/RoundTripTests.java
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/RoundTripTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2021 Willink Transformations and others.
+ * Copyright (c) 2010, 2022 Willink Transformations and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at