[508073] Avoid requiring a Pivot model
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/library/UnboxedCompositionProperty.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/library/UnboxedCompositionProperty.java
index 0d22619..d033586 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/library/UnboxedCompositionProperty.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/library/UnboxedCompositionProperty.java
@@ -10,14 +10,20 @@
*******************************************************************************/
package org.eclipse.ocl.pivot.internal.library;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.ocl.pivot.Element;
import org.eclipse.ocl.pivot.evaluation.Executor;
+import org.eclipse.ocl.pivot.ids.NestedPackageId;
+import org.eclipse.ocl.pivot.ids.NestedTypeId;
+import org.eclipse.ocl.pivot.ids.NsURIPackageId;
+import org.eclipse.ocl.pivot.ids.PackageId;
import org.eclipse.ocl.pivot.ids.PropertyId;
+import org.eclipse.ocl.pivot.ids.RootPackageId;
import org.eclipse.ocl.pivot.ids.TypeId;
import org.eclipse.ocl.pivot.library.AbstractProperty;
@@ -49,25 +55,58 @@
EObject eObject = (EObject)sourceValue;
EObject eContainer = eObject.eContainer();
if (eContainer == null) {
- return null; // No container
- }
- EStructuralFeature eFeature2 = eFeature;
- if (eFeature2 == null) {
- PropertyId propertyId2 = propertyId;
- if (propertyId2 != null) {
- Element asProperty = executor.getIdResolver().visitPropertyId(propertyId2);
- eFeature = eFeature2 = (EStructuralFeature) asProperty.getESObject();
- }
+ return null; // No container
}
EReference eContainmentFeature = eObject.eContainmentFeature();
- if (eFeature != null) {
- if (eContainmentFeature != eFeature) {
- return null; // Contained but by some other property
+ EStructuralFeature eFeature2 = eFeature;
+ if (eFeature2 != null) {
+ if (eContainmentFeature != eFeature2) {
+ return null; // Contained but by some other property
}
}
else {
- if (!containmentFeatureName.equals(eContainmentFeature.getName())) {
- return null; // Contained but by some other property
+ PropertyId propertyId2 = propertyId;
+ if (propertyId2 == null) {
+ if (!containmentFeatureName.equals(eContainmentFeature.getName())) {
+ return null; // Contained but by some other property
+ }
+ eFeature = eContainmentFeature;
+ }
+ else {
+ if (!propertyId2.getName().equals(eContainmentFeature.getName())) {
+ return null; // Contained but by some other property
+ }
+ NestedTypeId typeId = (NestedTypeId) propertyId2.getParent();
+ EClass eClass = eContainmentFeature.getEContainingClass();
+ if (!typeId.getName().equals(eClass.getName())) {
+ return null; // Contained but by some other property
+ }
+ PackageId packageId = typeId.getParent();
+ EPackage ePackage = eClass.getEPackage();
+ while (packageId instanceof NestedPackageId) {
+ if (!((NestedPackageId)packageId).getName().equals(ePackage.getName())) {
+ return null; // Contained but by some other property
+ }
+ packageId = ((NestedPackageId)packageId).getParent();
+ ePackage = ePackage.getESuperPackage();
+ if (ePackage == null) {
+ return null; // Contained but by some other property
+ }
+ }
+ if (packageId instanceof NsURIPackageId) {
+ if (!((NsURIPackageId)packageId).getNsURI().equals(ePackage.getNsURI())) {
+ return null; // Contained but by some other property
+ }
+ }
+ else if (packageId instanceof RootPackageId) {
+ if (!((RootPackageId)packageId).getName().equals(ePackage.getName())) {
+ return null; // Contained but by some other property
+ }
+ }
+ else {
+ throw new UnsupportedOperationException();
+ }
+ eFeature = eContainmentFeature;
}
}
return eContainer;