[cleanup] Refactor code of ResourceStrategy

This commit only pulls up a part of the
org.eclipse.sirius.business.internal.resource.strategy.DefaultResourceStrategyImpl.releaseResourceAtResourceSetDispose(Resource,
IProgressMonitor) method into
org.eclipse.sirius.business.api.resource.strategy.AbstractResourceStrategyImpl.clearEAdapters(Resource)
to allow to reuse this code in other ResourceStrategy.

Change-Id: I73d4b4748968c2bb8ec3956a3a12c0813a2ab5ef
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/resource/strategy/AbstractResourceStrategyImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/resource/strategy/AbstractResourceStrategyImpl.java
index fab20a1..da7b12d 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/resource/strategy/AbstractResourceStrategyImpl.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/resource/strategy/AbstractResourceStrategyImpl.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2017 Obeo.
+ * Copyright (c) 2017, 2020 Obeo.
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
  * which accompanies this distribution, and is available at
@@ -18,9 +18,12 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.TreeIterator;
 import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.sirius.business.api.resource.LoadEMFResource;
 import org.eclipse.sirius.business.api.session.Session;
 import org.eclipse.sirius.common.tools.api.resource.ResourceSetFactory;
@@ -55,10 +58,9 @@
 
     /**
      * Corresponding to default Sirius implementation (
-     * {@link org.eclipse.sirius.business.internal.resource.strategy.DefaultResourceStrategyImpl}
-     * ). It is not used in this abstract ResourceStrategy as canHandle methods
-     * return false. It is in this abstract class to be easily used by sub
-     * classes.
+     * {@link org.eclipse.sirius.business.internal.resource.strategy.DefaultResourceStrategyImpl} ). It is not used in
+     * this abstract ResourceStrategy as canHandle methods return false. It is in this abstract class to be easily used
+     * by sub classes.
      */
     @Override
     public boolean isPotentialSemanticResource(URI uri) {
@@ -71,10 +73,9 @@
 
     /**
      * Corresponding to default Sirius implementation (
-     * {@link org.eclipse.sirius.business.internal.resource.strategy.DefaultResourceStrategyImpl}
-     * ). It is not used in this abstract ResourceStrategy as canHandle methods
-     * return false. It is in this abstract class to be easily used by sub
-     * classes.
+     * {@link org.eclipse.sirius.business.internal.resource.strategy.DefaultResourceStrategyImpl} ). It is not used in
+     * this abstract ResourceStrategy as canHandle methods return false. It is in this abstract class to be easily used
+     * by sub classes.
      */
     @Override
     public boolean isLoadableModel(URI uri, Session session) {
@@ -89,4 +90,26 @@
         }
         return false;
     }
+
+    /**
+     * Clear the eAdapters list of all {@link EObject} of this {@link Resource}, if this {@link Resource} is from the
+     * package registry.
+     * 
+     * @param resource
+     *            The concerned resource.
+     */
+    protected void clearEAdapters(Resource resource) {
+        if (!isFromPackageRegistry(resource)) {
+            TreeIterator<EObject> allContents = EcoreUtil.getAllProperContents(resource, false);
+            while (allContents.hasNext()) {
+                EObject eObject = allContents.next();
+                eObject.eAdapters().clear();
+            }
+        }
+    }
+
+    private boolean isFromPackageRegistry(Resource resource) {
+        URI uri = resource.getURI();
+        return uri != null && resource.getResourceSet().getPackageRegistry().getEPackage(uri.toString()) != null;
+    }
 }
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/resource/strategy/DefaultResourceStrategyImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/resource/strategy/DefaultResourceStrategyImpl.java
index 0d23a75..2873a01 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/resource/strategy/DefaultResourceStrategyImpl.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/resource/strategy/DefaultResourceStrategyImpl.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2016, 2017 Obeo.
+ * Copyright (c) 2016, 2020 Obeo.
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
  * which accompanies this distribution, and is available at
@@ -17,21 +17,16 @@
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.util.TreeIterator;
 import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.sirius.business.api.query.URIQuery;
 import org.eclipse.sirius.business.api.resource.strategy.AbstractResourceStrategyImpl;
 import org.eclipse.sirius.viewpoint.SiriusPlugin;
 
 /**
- * Represents the default resource strategy used by Sirius. The implementation
- * of type {@link ResourceStrategyType#RELEASE_RESOURCE_AT_RESOURCESET_DISPOSE}
- * is optimized compared to the legacy one (
- * {@link org.eclipse.sirius.business.api.resource.strategy.LegacyReleaseResourceStrategyImpl}
- * .
+ * Represents the default resource strategy used by Sirius. The implementation of type
+ * {@link ResourceStrategyType#RELEASE_RESOURCE_AT_RESOURCESET_DISPOSE} is optimized compared to the legacy one (
+ * {@link org.eclipse.sirius.business.api.resource.strategy.LegacyReleaseResourceStrategyImpl} .
  * 
  * 
  * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a>
@@ -46,21 +41,12 @@
             // InMemory resources must be unloaded explicitly for their memory
             // buffers to be released.
             resource.unload();
-        } else if (!isFromPackageRegistry(resource)) {
-            TreeIterator<EObject> allContents = EcoreUtil.getAllProperContents(resource, false);
-            while (allContents.hasNext()) {
-                EObject eObject = allContents.next();
-                eObject.eAdapters().clear();
-            }
+        } else {
+            clearEAdapters(resource);
         }
         return new Status(IStatus.INFO, SiriusPlugin.ID, ""); //$NON-NLS-1$
     }
 
-    private boolean isFromPackageRegistry(Resource resource) {
-        URI uri = resource.getURI();
-        return uri != null && resource.getResourceSet().getPackageRegistry().getEPackage(uri.toString()) != null;
-    }
-
     @Override
     public boolean canHandle(URI resourceURI, ResourceStrategyType resourceStrategyType) {
         // All ResourceStrategyType is handled by default by this