Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Constant2019-10-02 08:41:54 +0000
committerOlivier Constant2019-10-02 08:41:54 +0000
commitf6e43188bff25bf64a3c32515171cba34e0ffe6c (patch)
treee6836ab5ef22b64b680e3a12130f7d68f7e5dea4
parent83faa4e19a0278fcbfcc281109c7716b620d4d43 (diff)
downloadorg.eclipse.emf.diffmerge.core-f6e43188bff25bf64a3c32515171cba34e0ffe6c.tar.gz
org.eclipse.emf.diffmerge.core-f6e43188bff25bf64a3c32515171cba34e0ffe6c.tar.xz
org.eclipse.emf.diffmerge.core-f6e43188bff25bf64a3c32515171cba34e0ffe6c.zip
Suppressed risk of stack overflow in Sirius logical scopesv0.12.0
Change-Id: Ie06dbb772c153c0e744bc403b7b98c2c52dc030b Signed-off-by: Olivier Constant <olivier.constant@thalesgroup.com>
-rw-r--r--plugins/org.eclipse.emf.diffmerge.sirius/src/org/eclipse/emf/diffmerge/sirius/SiriusMergePolicy.java8
-rw-r--r--plugins/org.eclipse.emf.diffmerge.sirius/src/org/eclipse/emf/diffmerge/sirius/SiriusScope.java25
-rw-r--r--plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/api/scopes/IPersistentModelScope.java6
-rw-r--r--plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/impl/scopes/FragmentedModelScope.java16
-rw-r--r--plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/impl/scopes/SubtreeModelScope.java9
5 files changed, 50 insertions, 14 deletions
diff --git a/plugins/org.eclipse.emf.diffmerge.sirius/src/org/eclipse/emf/diffmerge/sirius/SiriusMergePolicy.java b/plugins/org.eclipse.emf.diffmerge.sirius/src/org/eclipse/emf/diffmerge/sirius/SiriusMergePolicy.java
index a771ef0e..3d5ae505 100644
--- a/plugins/org.eclipse.emf.diffmerge.sirius/src/org/eclipse/emf/diffmerge/sirius/SiriusMergePolicy.java
+++ b/plugins/org.eclipse.emf.diffmerge.sirius/src/org/eclipse/emf/diffmerge/sirius/SiriusMergePolicy.java
@@ -14,6 +14,7 @@ package org.eclipse.emf.diffmerge.sirius;
import java.util.Set;
import org.eclipse.emf.diffmerge.api.scopes.IFeaturedModelScope;
+import org.eclipse.emf.diffmerge.api.scopes.IPersistentModelScope;
import org.eclipse.emf.diffmerge.gmf.GMFMergePolicy;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
@@ -73,11 +74,12 @@ public class SiriusMergePolicy extends GMFMergePolicy {
}
}
} else if (container == null) {
- DRepresentationDescriptor descriptor;
+ DRepresentationDescriptor descriptor = null;
if (scope_p instanceof SiriusScope) {
descriptor = ((SiriusScope)scope_p).getRepresentationDescriptor(element_p);
- } else {
- descriptor = SiriusScope.getRepresentationDescriptorByExploration(element_p, scope_p);
+ } else if (scope_p instanceof IPersistentModelScope) {
+ descriptor = SiriusScope.getRepresentationDescriptorByPhysicalExploration(
+ element_p, (IPersistentModelScope)scope_p);
}
if (descriptor != null) {
group_p.add(descriptor);
diff --git a/plugins/org.eclipse.emf.diffmerge.sirius/src/org/eclipse/emf/diffmerge/sirius/SiriusScope.java b/plugins/org.eclipse.emf.diffmerge.sirius/src/org/eclipse/emf/diffmerge/sirius/SiriusScope.java
index c69d18d1..f7b8d8b8 100644
--- a/plugins/org.eclipse.emf.diffmerge.sirius/src/org/eclipse/emf/diffmerge/sirius/SiriusScope.java
+++ b/plugins/org.eclipse.emf.diffmerge.sirius/src/org/eclipse/emf/diffmerge/sirius/SiriusScope.java
@@ -21,7 +21,7 @@ import java.util.Map;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.diffmerge.api.scopes.IModelScope;
+import org.eclipse.emf.diffmerge.api.scopes.IPersistentModelScope;
import org.eclipse.emf.diffmerge.gmf.GMFScope;
import org.eclipse.emf.diffmerge.structures.common.FArrayList;
import org.eclipse.emf.ecore.EObject;
@@ -256,7 +256,7 @@ public class SiriusScope extends GMFScope {
DRepresentationQuery rep2descQuery = new DRepresentationQuery(representation_p);
result = rep2descQuery.getRepresentationDescriptor();
if (result == null) {
- result = getRepresentationDescriptorByExploration(representation_p, this);
+ result = getRepresentationDescriptorByExploration(representation_p);
}
if (result != null) {
registerRepresentationDescriptor(result);
@@ -267,14 +267,27 @@ public class SiriusScope extends GMFScope {
/**
* Find and return the descriptor for the given representation, if any, by simple exploration
- * of the given scope. It is assumed that Sirius DAnalyses are roots of the scope.
+ * of this scope
+ * @param representation_p a non-null representation
+ * @return a potentially null descriptor
+ */
+ protected DRepresentationDescriptor getRepresentationDescriptorByExploration(
+ DRepresentation representation_p) {
+ return getRepresentationDescriptorByPhysicalExploration(representation_p, this);
+ }
+
+ /**
+ * Find and return the descriptor for the given representation, if any, by simple exploration
+ * of the given scope. It is assumed that Sirius DAnalyses are physical roots of the scope.
* The scope does not have to be a Sirius scope.
* @param representation_p a non-null representation
+ * @param scope_p a non-null scope
* @return a potentially null descriptor
*/
- public static DRepresentationDescriptor getRepresentationDescriptorByExploration(
- DRepresentation representation_p, IModelScope scope_p) {
- for (EObject root : scope_p.getContents()) {
+ public static DRepresentationDescriptor getRepresentationDescriptorByPhysicalExploration(
+ DRepresentation representation_p, IPersistentModelScope scope_p) {
+ List<EObject> roots = scope_p.getRawContents();
+ for (EObject root : roots) {
if (root instanceof DAnalysis) {
for (DView view : ((DAnalysis)root).getOwnedViews()) {
for (DRepresentationDescriptor descriptor : view.getOwnedRepresentationDescriptors()) {
diff --git a/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/api/scopes/IPersistentModelScope.java b/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/api/scopes/IPersistentModelScope.java
index a7047bb7..eebbe450 100644
--- a/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/api/scopes/IPersistentModelScope.java
+++ b/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/api/scopes/IPersistentModelScope.java
@@ -40,6 +40,12 @@ public interface IPersistentModelScope extends IModelScope {
Object getExtrinsicID(EObject element_p);
/**
+ * Return the root elements of this scope from a physical (non-logical) perspective
+ * @return a non-null, potentially empty list
+ */
+ List<EObject> getRawContents();
+
+ /**
* Initialize the scope by loading at least the elements that are required
* for exploring the scope
* Postcondition: isLoaded() if no exception is thrown
diff --git a/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/impl/scopes/FragmentedModelScope.java b/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/impl/scopes/FragmentedModelScope.java
index 92fe8be1..67827562 100644
--- a/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/impl/scopes/FragmentedModelScope.java
+++ b/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/impl/scopes/FragmentedModelScope.java
@@ -307,10 +307,7 @@ implements IFragmentedModelScope.Editable, IEditingDomainProvider {
* Result is guaranteed to be accurate only if hasBeenExplored().
*/
public List<EObject> getContents() {
- List<EObject> result = new FArrayList<EObject>();
- for (Resource resource : _rootResources)
- result.addAll(resource.getContents());
- return Collections.unmodifiableList(result);
+ return getRawContents();
}
/**
@@ -373,6 +370,17 @@ implements IFragmentedModelScope.Editable, IEditingDomainProvider {
}
/**
+ * @see org.eclipse.emf.diffmerge.api.scopes.IFragmentedModelScope#getRawContents()
+ * Result is guaranteed to be accurate only if hasBeenExplored().
+ */
+ public List<EObject> getRawContents() {
+ List<EObject> result = new FArrayList<EObject>();
+ for (Resource resource : _rootResources)
+ result.addAll(resource.getContents());
+ return Collections.unmodifiableList(result);
+ }
+
+ /**
* @see org.eclipse.emf.diffmerge.api.scopes.IFragmentedModelScope#getReferencedResources(org.eclipse.emf.ecore.resource.Resource)
* Result is guaranteed to be accurate only if hasBeenExplored().
*/
diff --git a/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/impl/scopes/SubtreeModelScope.java b/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/impl/scopes/SubtreeModelScope.java
index de2817f1..f1f1ace6 100644
--- a/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/impl/scopes/SubtreeModelScope.java
+++ b/plugins/org.eclipse.emf.diffmerge/src/org/eclipse/emf/diffmerge/impl/scopes/SubtreeModelScope.java
@@ -76,7 +76,7 @@ implements IPersistentModelScope.Editable {
* @see org.eclipse.emf.diffmerge.api.scopes.IModelScope#getContents()
*/
public List<EObject> getContents() {
- return Collections.singletonList(getRoot());
+ return getRawContents();
}
/**
@@ -104,6 +104,13 @@ implements IPersistentModelScope.Editable {
}
/**
+ * @see org.eclipse.emf.diffmerge.api.scopes.IPersistentModelScope#getRawContents()
+ */
+ public List<EObject> getRawContents() {
+ return Collections.singletonList(getRoot());
+ }
+
+ /**
* Return the root of this scope
* @return a non-null element
*/

Back to the top