[496251] Support UML elements for OCLHelper methods
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/helper/OCLHelperImpl.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/helper/OCLHelperImpl.java
index 589d34f..91f5bb0 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/helper/OCLHelperImpl.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/helper/OCLHelperImpl.java
@@ -11,12 +11,10 @@
package org.eclipse.ocl.pivot.internal.helper;
-import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EOperation;
-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.ExpressionInOCL;
import org.eclipse.ocl.pivot.Operation;
import org.eclipse.ocl.pivot.Property;
@@ -50,38 +48,27 @@
*
* @param ocl the OCL environment
*/
- public OCLHelperImpl(@NonNull OCL ocl, @Nullable EObject context) {
+ public OCLHelperImpl(@NonNull OCL ocl, @Nullable EObject context) throws ParserException {
this.ocl = ocl;
this.context = context;
- if (context instanceof org.eclipse.ocl.pivot.Class) {
- contextClass = (org.eclipse.ocl.pivot.Class)context;
+ Element asContext;
+ if (context instanceof Element) {
+ asContext = (Element)context;
+ }
+ else {
+ asContext = getMetamodelManager().getASOf(Element.class, context);
+ }
+ if (asContext instanceof org.eclipse.ocl.pivot.Class) {
+ contextClass = (org.eclipse.ocl.pivot.Class)asContext;
}
- else if (context instanceof Operation) {
- contextOperation = (Operation)context;
+ else if (asContext instanceof Operation) {
+ contextOperation = (Operation)asContext;
contextClass = contextOperation.getOwningClass();
}
- else if (context instanceof Property) {
- contextProperty = (Property)context;
+ else if (asContext instanceof Property) {
+ contextProperty = (Property)asContext;
contextClass = contextProperty.getOwningClass();
}
- else if (context instanceof EClassifier) {
- contextClass = getMetamodelManager().getASOfEcore(org.eclipse.ocl.pivot.Class.class, context);
- }
- else if (context instanceof EOperation) {
- contextOperation = getMetamodelManager().getASOfEcore(Operation.class, context);
- if (contextOperation != null) {
- contextClass = contextOperation.getOwningClass();
- }
- }
- else if (context instanceof EStructuralFeature) {
- contextProperty = getMetamodelManager().getASOfEcore(Property.class, context);
- if (contextProperty != null) {
- contextClass = contextProperty.getOwningClass();
- }
- }
- else if (context instanceof EStructuralFeature) {
- contextClass = null;
- }
}
@Override
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/OCL.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/OCL.java
index ac2ea09..c1652f4 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/OCL.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/OCL.java
@@ -273,7 +273,7 @@
*
* @return a new helper object
*/
- public @NonNull OCLHelper createOCLHelper(@Nullable EObject contextElement) {
+ public @NonNull OCLHelper createOCLHelper(@Nullable EObject contextElement) throws ParserException {
return new OCLHelperImpl(this, contextElement);
}