Skip to content
Snippets Groups Projects
Commit 091e41a8 authored by Andreas Bayha's avatar Andreas Bayha
Browse files

Reuse: Remove all references before adding elemtn to library

before adding an element to a library, all references directing
"outside" of the component are removed, since those would break.
Containment relations are kept, since these elements are reused with the
parent.

Issue-ref: 4346
Issue-URL: af3#4346



Signed-off-by: default avatarAndreas Bayha <bayha@fortiss.org>
parent 76b90e1c
No related branches found
No related tags found
1 merge request!2194346
IReuseProvider.java 18d293f7f1f072883188f16fb6eeb52c8d6042cf GREEN
IReuseProviderService.java bcc70de0bb8d39c330e3a25d884abc7092dc1b7e GREEN
LayoutedReuseProviderBase.java b0e4ce3cda818b0723ec37b925a4c4c3d0c41909 GREEN
ReuseProviderBase.java ac47f5ecafed0bdef6ef5183c7194aa756f723fd GREEN
ReuseProviderBase.java c956ba13df1b7b5c8dbd7cd1a9205a06b5cebba1 YELLOW
ReuseProviderService.java c4ef33283002d6dac6167f9c6c8f71d2c2ce39d1 GREEN
......@@ -20,9 +20,11 @@ import static org.fortiss.tooling.ext.variability.util.VariabilityUtils.getOptVa
import static org.fortiss.tooling.kernel.utils.EcoreUtils.replaceEObjectReferences;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.element.IHierarchicElementContainer;
import org.fortiss.tooling.base.model.element.IModelElement;
......@@ -48,6 +50,9 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> {
if(reuseElement instanceof IModelElement) {
removeVariabilitySpecifications((IModelElement)reuseElement);
}
removeExternalReferences(reuseElement);
return true;
}
......@@ -124,4 +129,35 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> {
}
}
}
/**
* Recursively removes all external (i.e. non-containment) reference targets from this and all
* contained {@link EObject}s.
*
* @param eObj
* The {@link EObject} for which all reference targets shall be removed.
*/
@SuppressWarnings("unchecked")
private void removeExternalReferences(EObject eObj) {
for(EReference ref : eObj.eClass().getEReferences()) {
Object refTarget = eObj.eGet(ref);
if(refTarget == null) {
continue;
}
if(ref.isContainment()) {
// Containment relations must not be removed. Yet, references of childs need to be
// removed recursively.
if(refTarget instanceof Collection<?>) {
((Collection<EObject>)refTarget).stream()
.forEach(t -> removeExternalReferences(t));
} else {
removeExternalReferences((EObject)refTarget);
}
} else {
eObj.eSet(ref, null);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment