Skip to content

Commit 750ebb3

Browse files
authored
Merge pull request #645 from Systems-Modeling/ST6RI-840
ST6RI-840 Constructor expression evaluation (KERML_-224)
2 parents c365ffb + 4164bed commit 750ebb3

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/ModelLevelEvaluationTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,21 @@ public void testListEvaluation() throws Exception {
299299
assertEquals(true, evaluateBooleanValue(null, null, "SequenceFunctions::notEmpty((1,2,3))"));
300300
}
301301

302+
@Test
303+
public void testConstructorEvaluation() throws Exception {
304+
SysMLInteractive instance = getSysMLInteractiveInstance();
305+
process(instance,
306+
"part def P { attribute a; attribute b; } " +
307+
"part p1 = new P(1, 2); " +
308+
"part p2 = new P(b = p1.b, a = p1.a);");
309+
assertEquals(true, evaluateBooleanValue(instance, null, "p1 istype P"));
310+
assertEquals(1, evaluateIntegerValue(instance, null, "p1.a"));
311+
assertEquals(2, evaluateIntegerValue(instance, null, "p1.b"));
312+
assertEquals(true, evaluateBooleanValue(instance, null, "p2 istype P"));
313+
assertEquals(1, evaluateIntegerValue(instance, null, "p2.a"));
314+
assertEquals(2, evaluateIntegerValue(instance, null, "p2.b"));
315+
}
316+
302317
@Test
303318
public void testFeatureReferenceEvaluation() throws Exception {
304319
SysMLInteractive instance = getSysMLInteractiveInstance();

org.omg.sysml/src/org/omg/sysml/delegate/invocation/FeatureReferenceExpression_modelLevelEvaluable_InvocationDelegate.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2024 Model Driven Solutions, Inc.
3+
* Copyright (c) 2024, 2025 Model Driven Solutions, Inc.
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -55,19 +55,22 @@ public Object dynamicInvoke(InternalEObject target, EList<?> arguments) throws I
5555
return false;
5656
} else {
5757
visited.add(referent);
58+
boolean result;
5859
if (referent instanceof Expression && ((Expression) referent).modelLevelEvaluable(visited)) {
59-
return true;
60+
result = true;
6061
} else {
6162
Type owningType = referent.getOwningType();
6263
if (owningType instanceof Metaclass || owningType instanceof MetadataFeature) {
63-
return true;
64+
result = true;
6465
} else if (!referent.getFeaturingType().isEmpty()) {
65-
return false;
66+
result = false;
6667
} else {
6768
Expression valueExpression = FeatureUtil.getValueExpressionFor(referent);
68-
return valueExpression == null || valueExpression.modelLevelEvaluable(visited);
69+
result = valueExpression == null || valueExpression.modelLevelEvaluable(visited);
6970
}
7071
}
72+
visited.remove(referent);
73+
return result;
7174
}
7275
}
7376

org.omg.sysml/src/org/omg/sysml/expressions/ModelLevelExpressionEvaluator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2022 Model Driven Solutions, Inc.
3+
* Copyright (c) 2022, 2025 Model Driven Solutions, Inc.
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -30,6 +30,7 @@
3030
import org.omg.sysml.expressions.functions.LibraryFunction;
3131
import org.omg.sysml.expressions.util.EvaluationUtil;
3232
import org.omg.sysml.lang.sysml.AnnotatingElement;
33+
import org.omg.sysml.lang.sysml.ConstructorExpression;
3334
import org.omg.sysml.lang.sysml.Element;
3435
import org.omg.sysml.lang.sysml.Expression;
3536
import org.omg.sysml.lang.sysml.Feature;
@@ -74,6 +75,8 @@ public EList<Element> evaluate(Expression expression, Element target) {
7475
return evaluateMetadataAccess((MetadataAccessExpression)expression, target);
7576
} else if (expression instanceof InvocationExpression) {
7677
return evaluateInvocation((InvocationExpression)expression, target);
78+
} else if (expression instanceof ConstructorExpression) {
79+
return evaluateConstructor((ConstructorExpression)expression, target);
7780
} else {
7881
return new BasicEList<>();
7982
}
@@ -109,6 +112,11 @@ public EList<Element> evaluateInvocation(InvocationExpression expression, Elemen
109112
return function == null? EvaluationUtil.singletonList(expression): function.invoke(expression, target, this);
110113
}
111114

115+
public EList<Element> evaluateConstructor(ConstructorExpression expression, Element target) {
116+
Feature resultParameter = TypeUtil.getResultParameterOf(expression);
117+
return resultParameter == null? null: EvaluationUtil.singletonList(resultParameter);
118+
}
119+
112120
public EList<Element> evaluateFeature(Feature feature, Type type) {
113121
if (type != null && TypeUtil.specializes(feature, ExpressionUtil.getSelfReferenceFeature(feature))) {
114122
// Evaluate "self" feature. (Note: Must be checked before test for feature chain because "self" has chaining features.)

0 commit comments

Comments
 (0)