Skip to content

Commit 866ed2d

Browse files
committed
ST6RI-884 Refactored model-level evaluable library function impls.
- Moved implementations of all functions not considered model-level per the specification from org.omg.sysml.expressions.functions to org.omg.sysml.execution.expressions.functions. - Only library functions registered with the INSTANCE of org.omg.sysml.expressions.ModelLevelEvaluableLibraryFunctionFactory are now considered model-level evaluable.
1 parent f4aeb6f commit 866ed2d

21 files changed

Lines changed: 231 additions & 86 deletions

org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/ExpressionEvaluator.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.eclipse.emf.common.util.EList;
2525
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
26+
import org.omg.sysml.expressions.functions.LibraryFunction;
2627
import org.omg.sysml.expressions.util.EvaluationUtil;
2728
import org.omg.sysml.lang.sysml.Element;
2829
import org.omg.sysml.lang.sysml.Expression;
@@ -43,11 +44,17 @@ public class ExpressionEvaluator extends ModelLevelExpressionEvaluator {
4344

4445
public static final ExpressionEvaluator INSTANCE = new ExpressionEvaluator();
4546

47+
public ExpressionEvaluator() {
48+
super();
49+
setLibraryFunctionFactory(new LibraryFunctionFactory());
50+
}
51+
4652
@Override
4753
public EList<Element> evaluateInvocation(InvocationExpression expression, Element target) {
4854
Function function = expression.getFunction();
49-
if (function != null && function.isModelLevelEvaluable()) {
50-
return super.evaluateInvocation(expression, target);
55+
LibraryFunction libraryFunction = libraryFunctionFactory.getLibraryFunction(function);
56+
if (libraryFunction != null) {
57+
return libraryFunction.invoke(expression, target, this);
5158
} else {
5259
Type type = expression.instantiatedType();
5360
Expression resultExpression = null;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.execution.expressions;
23+
24+
import org.omg.sysml.execution.expressions.functions.*;
25+
26+
public class LibraryFunctionFactory extends org.omg.sysml.expressions.ModelLevelLibraryFunctionFactory {
27+
28+
public static final LibraryFunctionFactory INSTANCE = new LibraryFunctionFactory();
29+
30+
@Override
31+
protected void initializeFunctionMap() {
32+
super.initializeFunctionMap();
33+
34+
put(new SizeFunction());
35+
put(new IsEmptyFunction());
36+
put(new NotEmptyFunction());
37+
put(new IncludesFunction());
38+
put(new ExcludesFunction());
39+
40+
put(new SumFunction());
41+
put(new ProdFunction());
42+
43+
put(new StringLengthFunction());
44+
put(new StringSubstringFunction());
45+
}
46+
47+
}

org.omg.sysml/src/org/omg/sysml/expressions/functions/ExcludesFunction.java renamed to org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/functions/ExcludesFunction.java

Lines changed: 2 additions & 2 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) 2021, 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
@@ -18,7 +18,7 @@
1818
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
1919
*
2020
*******************************************************************************/
21-
package org.omg.sysml.expressions.functions;
21+
package org.omg.sysml.execution.expressions.functions;
2222

2323
import org.eclipse.emf.common.util.EList;
2424
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;

org.omg.sysml/src/org/omg/sysml/expressions/functions/IncludesFunction.java renamed to org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/functions/IncludesFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2021 Model Driven Solutions, Inc.
3+
* Copyright (c) 2021, 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
@@ -18,7 +18,7 @@
1818
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
1919
*
2020
*******************************************************************************/
21-
package org.omg.sysml.expressions.functions;
21+
package org.omg.sysml.execution.expressions.functions;
2222

2323
import org.eclipse.emf.common.util.EList;
2424
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;

org.omg.sysml/src/org/omg/sysml/expressions/functions/IsEmptyFunction.java renamed to org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/functions/IsEmptyFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2021 Model Driven Solutions, Inc.
3+
* Copyright (c) 2021, 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
@@ -18,7 +18,7 @@
1818
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
1919
*
2020
*******************************************************************************/
21-
package org.omg.sysml.expressions.functions;
21+
package org.omg.sysml.execution.expressions.functions;
2222

2323
import org.eclipse.emf.common.util.EList;
2424
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;

org.omg.sysml/src/org/omg/sysml/expressions/functions/NotEmptyFunction.java renamed to org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/functions/NotEmptyFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2021 Model Driven Solutions, Inc.
3+
* Copyright (c) 2021, 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
@@ -18,7 +18,7 @@
1818
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
1919
*
2020
*******************************************************************************/
21-
package org.omg.sysml.expressions.functions;
21+
package org.omg.sysml.execution.expressions.functions;
2222

2323
import org.eclipse.emf.common.util.EList;
2424
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of theGNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.execution.expressions.functions;
23+
24+
import org.omg.sysml.expressions.functions.LibraryFunction;
25+
26+
public abstract class NumericalFunction implements LibraryFunction {
27+
28+
@Override
29+
public String getPackageName() {
30+
return "NumericalFunctions";
31+
}
32+
33+
}

org.omg.sysml/src/org/omg/sysml/expressions/functions/ProdFunction.java renamed to org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/functions/ProdFunction.java

Lines changed: 3 additions & 8 deletions
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
@@ -19,7 +19,7 @@
1919
*
2020
*******************************************************************************/
2121

22-
package org.omg.sysml.expressions.functions;
22+
package org.omg.sysml.execution.expressions.functions;
2323

2424
import org.eclipse.emf.common.util.EList;
2525
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
@@ -29,13 +29,8 @@
2929
import org.omg.sysml.lang.sysml.LiteralInteger;
3030
import org.omg.sysml.lang.sysml.LiteralRational;
3131

32-
public class ProdFunction implements LibraryFunction {
32+
public class ProdFunction extends NumericalFunction {
3333

34-
@Override
35-
public String getPackageName() {
36-
return "NumericalFunctions";
37-
}
38-
3934
@Override
4035
public String getOperatorName() {
4136
return "product";

org.omg.sysml/src/org/omg/sysml/expressions/functions/SequenceFunction.java renamed to org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/functions/SequenceFunction.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2021 Model Driven Solutions, Inc.
3+
* Copyright (c) 2021, 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
@@ -19,7 +19,9 @@
1919
*
2020
*******************************************************************************/
2121

22-
package org.omg.sysml.expressions.functions;
22+
package org.omg.sysml.execution.expressions.functions;
23+
24+
import org.omg.sysml.expressions.functions.LibraryFunction;
2325

2426
public abstract class SequenceFunction implements LibraryFunction {
2527

org.omg.sysml/src/org/omg/sysml/expressions/functions/SizeFunction.java renamed to org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/functions/SizeFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2021 Model Driven Solutions, Inc.
3+
* Copyright (c) 2021, 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
@@ -18,7 +18,7 @@
1818
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
1919
*
2020
*******************************************************************************/
21-
package org.omg.sysml.expressions.functions;
21+
package org.omg.sysml.execution.expressions.functions;
2222

2323
import org.eclipse.emf.common.util.EList;
2424
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;

0 commit comments

Comments
 (0)