Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[582664] Detaching an element from and reattaching it to a model can lose stereotype application data #1

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.DiagnosticChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
Expand Down Expand Up @@ -892,6 +890,8 @@ public boolean isSetOwner() {
CHANGE_DESCRIPTION_CLASS = changeDescriptionClass;
}

private static final int DETACHED = 1 << 6;

@Override
public NotificationChain eBasicSetContainer(InternalEObject newContainer,
int newContainerFeatureID, NotificationChain msgs) {
Expand Down Expand Up @@ -942,24 +942,44 @@ && eContainmentFeature(this, newContainer,
}

if (CHANGE_DESCRIPTION_CLASS == null
|| !(CHANGE_DESCRIPTION_CLASS.isInstance(newContainer))) {
|| !(CHANGE_DESCRIPTION_CLASS.isInstance(newContainer))) {

Resource.Internal eInternalResource = eInternalResource();
if (eInternalResource == null || !eInternalResource.isLoading()) {

if (oldContainer != null) {
ElementOperations.unapplyAllNonApplicableStereotypes(this, false);
}

if (newContainer != null) {
ElementOperations.applyAllRequiredStereotypes(this, false);
}
if (eInternalResource == null || !eInternalResource.isLoading()) {
if (oldContainer == null) {
// ATTACH or REATTACH (newContainer can't be null, too)
if ((eFlags & DETACHED) != 0) {
// REATTACH (was detached before)
ElementOperations
.unapplyAllNonApplicableStereotypes(this, false);
ElementOperations.applyAllRequiredStereotypes(this,
false);
eFlags &= ~DETACHED; // Forget former detach
} else {
// ATTACH (wasn't detached before)
ElementOperations.applyAllRequiredStereotypes(this,
false);
}
} else {
// DETACH or MOVE
if (newContainer == null) {
// DETACH
eFlags |= DETACHED; // Remember detach
} else {
// MOVE
ElementOperations
.unapplyAllNonApplicableStereotypes(this, false);
ElementOperations.applyAllRequiredStereotypes(this,
false);
}
}
}
}

return msgs;
}

private static final int ADAPTING = 1 << 7;

@Override
Expand Down