Skip to content

Commit 11819a0

Browse files
committed
ST6RI-971 Fixed evaluation of enumeration-typed meta-properties.
- Extended EvaluationUtil.elementFor and results to handle metamodel enum values. - Revised the use of EvaluationUtil.results in ModelLevelExpressionEvaluatior.
1 parent 7b79cf9 commit 11819a0

4 files changed

Lines changed: 27 additions & 11 deletions

File tree

Binary file not shown.

‎org.omg.sysml.logic/src/main/java/org/omg/sysml/expressions/ModelLevelExpressionEvaluator.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ public EList<Element> evaluateFeature(Feature feature, Type type) {
156156
Type t = types.get(i);
157157
if (t instanceof MetadataFeature && TypeUtil.specializes(feature, EvaluationUtil.getAnnotatedElementFeature((MetadataFeature)t))) {
158158
// Evaluate "Metaobject::annotatedElement" feature.
159-
return EvaluationUtil.results(((MetadataFeature)t).getAnnotatedElement());
159+
return EvaluationUtil.results(feature, ((MetadataFeature)t).getAnnotatedElement());
160160
} else if (EvaluationUtil.isMetaclassFeature(t)) {
161161
if (!(feature instanceof Expression)) {
162162
// Evaluate the feature as a reflective metaclass attribute.
163163
Element element = ((AnnotatingElement)t).getAnnotatedElement().get(0);
164164
EStructuralFeature eFeature = element.eClass().getEStructuralFeature(feature.getDeclaredName());
165165
if (eFeature != null) {
166-
return EvaluationUtil.results(element.eGet(eFeature, true));
166+
return EvaluationUtil.results(feature, element.eGet(eFeature, true));
167167
}
168168
}
169169
} else {

‎org.omg.sysml.logic/src/main/java/org/omg/sysml/util/EvaluationUtil.java‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static Expression expressionFor(EList<Element> results, Element context)
129129
public static Expression expressionFor(Element result) {
130130
if (result instanceof LiteralExpression) {
131131
Object value = valueOf(result);
132-
return value == null? literalInfinity(): (Expression)elementFor(value);
132+
return value == null? literalInfinity(): (Expression)elementFor(null, value);
133133
} else if (result instanceof Feature) {
134134
FeatureReferenceExpression featureRef = SysMLFactory.eINSTANCE.createFeatureReferenceExpression();
135135
NamespaceUtil.addMemberTo(featureRef, result);
@@ -140,29 +140,29 @@ public static Expression expressionFor(Element result) {
140140

141141
}
142142

143-
public static EList<Element> results(Object object) {
143+
public static EList<Element> results(Element context, Object object) {
144144
EList<Element> results = new BasicEList<>();
145-
if (object instanceof List) {
146-
((List<?>)object).stream().
147-
map(EvaluationUtil::elementFor).
145+
if (object instanceof List<?> list) {
146+
list.stream().
147+
map(obj->elementFor(context, obj)).
148148
filter(e->e != null).
149149
forEachOrdered(results::add);
150150
} else if (object != null) {
151-
Element element = elementFor(object);
152-
if (object != null) {
151+
Element element = elementFor(context, object);
152+
if (element != null) {
153153
results.add(element);
154154
}
155155
}
156156
return results;
157157
}
158158

159-
public static Element elementFor(Object object) {
159+
public static Element elementFor(Element context, Object object) {
160160
return object instanceof Boolean? literalBoolean((Boolean)object):
161161
object instanceof String? literalString((String)object):
162162
object instanceof Integer? literalInteger((Integer)object):
163163
object instanceof Double? literalRational((Double)object):
164164
object instanceof Element? ElementUtil.getMetaclassFeatureFor((Element)object):
165-
null;
165+
enumUsage(context, object);
166166
}
167167

168168
public static LiteralBoolean literalBoolean(boolean value) {
@@ -193,6 +193,22 @@ public static LiteralInfinity literalInfinity() {
193193
return SysMLFactory.eINSTANCE.createLiteralInfinity();
194194
}
195195

196+
public static Feature enumUsage(Element context, Object object) {
197+
if (object != null) {
198+
Class<?> class_ = object.getClass();
199+
if (class_ != null) {
200+
String name = class_.getSimpleName() + "::" + object;
201+
Type type = SysMLLibraryUtil.getLibraryType(context,
202+
"KerML::Root::" + name, "KerML::Core::" + name, "KerML::Kernel::" + name,
203+
"SysML::Systems::" + name);
204+
if (type instanceof Feature feature) {
205+
return feature;
206+
}
207+
}
208+
}
209+
return null;
210+
}
211+
196212
public static EList<Element> booleanResult(boolean value) {
197213
return singletonList(literalBoolean(value));
198214
}
Binary file not shown.

0 commit comments

Comments
 (0)