Skip to content
Snippets Groups Projects
Commit 9d8ff4de authored by Sebastian Bergemann's avatar Sebastian Bergemann
Browse files

1x RED (+ small comment changes, etc.)

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



Signed-off-by: default avatarSebastian Bergemann <bergemann@fortiss.org>
parent b2415278
No related branches found
No related tags found
1 merge request!2194346
Pipeline #39657 failed
......@@ -134,22 +134,20 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> {
}
/**
* Recursively removes all external (i.e. non-containment) reference targets from this and all
* Recursively removes all external (i.e., non-containment) reference targets from this and all
* contained {@link EObject}s.
*
* FIXME #4150 (https://git.fortiss.org/af3/af3/-/issues/4150): This functionality should be
* removed, as soon as there is a dedicated management of external references.
*
* @param eObj
* @param element
* The {@link EObject} for which all reference targets shall be removed.
*/
private void removeExternalReferences(EObject eObj) {
// whitelist all contained elements as reference targets.
Set<EObject> whitelist = new HashSet<EObject>(getChildrenWithType(eObj, EObject.class));
private void removeExternalReferences(EObject element) {
// Whitelist all contained elements as reference targets.
Set<EObject> whitelist = new HashSet<EObject>(getChildrenWithType(element, EObject.class));
// FIXME #4150 (https://git.fortiss.org/af3/af3/-/issues/4150): This functionality should be
// removed, as soon as there is a dedicated management of external references.
removeReferences(eObj, whitelist);
removeReferences(element, whitelist);
}
/**
......@@ -160,9 +158,12 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> {
* removed, as soon as there is a dedicated management of external references.
*/
@SuppressWarnings("unchecked")
private void removeReferences(EObject eObj, Set<EObject> whitelist) {
for(EReference ref : eObj.eClass().getEReferences()) {
Object refTarget = eObj.eGet(ref);
private void removeReferences(EObject element, Set<EObject> whitelist) {
// FIXME (SeB): the loop below does not get all internal/nested references, which is why it
// will skip the removals of internal references due to no direct references in the given
// element.
for(EReference ref : element.eClass().getEReferences()) {
Object refTarget = element.eGet(ref);
if(refTarget == null) {
continue;
......@@ -172,15 +173,12 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> {
Collection<EObject> refTargetCollection = (Collection<EObject>)refTarget;
if(ref.isContainment()) {
// Containment relations must not be removed. Yet, references of childs need to
// be removed recursively.
refTargetCollection.stream().forEach(t -> removeReferences(t, whitelist));
// Containment relations must not be removed. Yet, references of children need
// to be removed recursively.
refTargetCollection.stream()
.forEach(target -> removeReferences(target, whitelist));
} else {
for(EObject t : refTargetCollection) {
if(!whitelist.contains(t)) {
refTargetCollection.remove(t);
}
}
refTargetCollection.removeIf(target -> !whitelist.contains(target));
}
} else {
if(ref.isContainment()) {
......@@ -188,7 +186,7 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> {
removeReferences((EObject)refTarget, whitelist);
} else {
if(!whitelist.contains(refTarget)) {
eObj.eSet(ref, null);
element.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