-
Notifications
You must be signed in to change notification settings - Fork 47
ST6RI-886 Evaluation of functions from additional model libraries #727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f99b275
ST6RI-886 Reorganized package structure library function impl classes.
seidewitz 27a5698
ST6RI-886 Implemented all functions in SequenceFunctions package.
seidewitz 78247a3
ST6RI-886 Added Junit tests for CollectionFunctions.
seidewitz d3c89be
ST6RI-886 Fixed EvaluationUtil::expressionFor for lists and body exprs.
seidewitz a83e872
ST6RI-886 Implemented model-level eval of equality ops on collections.
seidewitz b6822f4
ST6RI-886 Implemented remaining functions in ControlFunctions package.
seidewitz d9bb651
ST6RI-886 Corrected local variable naming in MinimizeFunction.
seidewitz 177e6c3
ST6RI-886 Updated copyright date on LibraryFunctionFactory.java.
seidewitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...l.execution/src/org/omg/sysml/execution/expressions/functions/control/ExistsFunction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /******************************************************************************* | ||
| * SysML 2 Pilot Implementation | ||
| * Copyright (c) 2026 Model Driven Solutions, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| * @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later> | ||
| * | ||
| *******************************************************************************/ | ||
| package org.omg.sysml.execution.expressions.functions.control; | ||
|
|
||
| import org.eclipse.emf.common.util.EList; | ||
| import org.omg.sysml.expressions.ModelLevelExpressionEvaluator; | ||
| import org.omg.sysml.lang.sysml.Element; | ||
| import org.omg.sysml.lang.sysml.InvocationExpression; | ||
| import org.omg.sysml.util.EvaluationUtil; | ||
|
|
||
| public class ExistsFunction extends ForAllFunction { | ||
|
|
||
| @Override | ||
| public String getOperatorName() { | ||
| return "exists"; | ||
| } | ||
|
|
||
| @Override | ||
| public EList<Element> invoke(InvocationExpression invocation, Element target, | ||
| ModelLevelExpressionEvaluator evaluator) { | ||
| Boolean result = forAll(invocation, target, evaluator, false); | ||
| return result == null? EvaluationUtil.singletonList(invocation): EvaluationUtil.booleanResult(!result); | ||
| } | ||
|
|
||
| } |
68 changes: 68 additions & 0 deletions
68
...l.execution/src/org/omg/sysml/execution/expressions/functions/control/ForAllFunction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /******************************************************************************* | ||
| * SysML 2 Pilot Implementation | ||
| * Copyright (c) 2026 Model Driven Solutions, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| * @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later> | ||
| * | ||
| *******************************************************************************/ | ||
| package org.omg.sysml.execution.expressions.functions.control; | ||
|
|
||
| import org.eclipse.emf.common.util.EList; | ||
| import org.omg.sysml.expressions.ModelLevelExpressionEvaluator; | ||
| import org.omg.sysml.expressions.functions.control.ControlFunction; | ||
| import org.omg.sysml.lang.sysml.Element; | ||
| import org.omg.sysml.lang.sysml.Expression; | ||
| import org.omg.sysml.lang.sysml.InvocationExpression; | ||
| import org.omg.sysml.util.EvaluationUtil; | ||
|
|
||
| public class ForAllFunction extends ControlFunction { | ||
|
|
||
| @Override | ||
| public String getOperatorName() { | ||
| return "forAll"; | ||
| } | ||
|
|
||
| public Boolean forAll(InvocationExpression invocation, Element target, | ||
| ModelLevelExpressionEvaluator evaluator, Boolean test) { | ||
| EList<Element> list = evaluator.evaluateArgument(invocation, 0, target); | ||
| Element expr = evaluator.argumentValue(invocation, 1, target); | ||
| if (list == null || !(expr instanceof Expression)) { | ||
| return null; | ||
| } else { | ||
| for (Element value: list) { | ||
| if (value == null) { | ||
| return null; | ||
| } else { | ||
| EList<Element> exprValue = evaluator.evaluateExpression((Expression)expr, target, value); | ||
| if (exprValue == null || exprValue.size() != 1) { | ||
| return null; | ||
| } else if (!test.equals(EvaluationUtil.valueOf(exprValue.get(0)))) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public EList<Element> invoke(InvocationExpression invocation, Element target, | ||
| ModelLevelExpressionEvaluator evaluator) { | ||
| Boolean result = forAll(invocation, target, evaluator, true); | ||
| return result == null? EvaluationUtil.singletonList(invocation): EvaluationUtil.booleanResult(result); | ||
| } | ||
|
|
||
| } |
71 changes: 71 additions & 0 deletions
71
...execution/src/org/omg/sysml/execution/expressions/functions/control/MaximizeFunction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /******************************************************************************* | ||
| * SysML 2 Pilot Implementation | ||
| * Copyright (c) 2026 Model Driven Solutions, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| * @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later> | ||
| * | ||
| *******************************************************************************/ | ||
| package org.omg.sysml.execution.expressions.functions.control; | ||
|
|
||
| import java.util.function.BiFunction; | ||
|
|
||
| import org.eclipse.emf.common.util.EList; | ||
| import org.omg.sysml.expressions.ModelLevelExpressionEvaluator; | ||
| import org.omg.sysml.lang.sysml.Element; | ||
| import org.omg.sysml.lang.sysml.Expression; | ||
| import org.omg.sysml.lang.sysml.InvocationExpression; | ||
| import org.omg.sysml.lang.sysml.Type; | ||
| import org.omg.sysml.lang.sysml.util.SysMLLibraryUtil; | ||
| import org.omg.sysml.util.EvaluationUtil; | ||
|
|
||
| public class MaximizeFunction extends ReduceFunction { | ||
| private static final String MAX_FUNCTION = "DataFunctions::max"; | ||
|
|
||
| @Override | ||
| public String getOperatorName() { | ||
| return "maximize"; | ||
| } | ||
|
|
||
| @Override | ||
| public EList<Element> invoke(InvocationExpression invocation, Element target, | ||
| ModelLevelExpressionEvaluator evaluator) { | ||
| EList<Element> list = evaluator.evaluateArgument(invocation, 0, target); | ||
| Element expr = evaluator.argumentValue(invocation, 1, target); | ||
| if (list == null || !(expr instanceof Expression)) { | ||
| return EvaluationUtil.singletonList(invocation); | ||
| } else if (list.isEmpty()) { | ||
| return EvaluationUtil.nullList(); | ||
| } else { | ||
| return reduce(invocation, list, new BiFunction<>() { | ||
| @Override | ||
| public Element apply(Element result, Element value) { | ||
| EList<Element> exprValue = evaluator.evaluateExpression((Expression)expr, target, value); | ||
| if (exprValue == null || exprValue.size() != 1) { | ||
| return null; | ||
| } else if (result == null) { | ||
| return exprValue.get(0); | ||
| } else { | ||
| Type maxFunction = SysMLLibraryUtil.getLibraryType(expr, MAX_FUNCTION); | ||
| InvocationExpression maxInvocation = EvaluationUtil.createInvocationOf(maxFunction, result, exprValue.get(0)); | ||
| EList<Element> newResult = evaluator.evaluateInvocation(maxInvocation, target); | ||
| return newResult == null || newResult.size() != 1? null: newResult.get(0); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| } |
71 changes: 71 additions & 0 deletions
71
...execution/src/org/omg/sysml/execution/expressions/functions/control/MinimizeFunction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /******************************************************************************* | ||
| * SysML 2 Pilot Implementation | ||
| * Copyright (c) 2026 Model Driven Solutions, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| * @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later> | ||
| * | ||
| *******************************************************************************/ | ||
| package org.omg.sysml.execution.expressions.functions.control; | ||
|
|
||
| import java.util.function.BiFunction; | ||
|
|
||
| import org.eclipse.emf.common.util.EList; | ||
| import org.omg.sysml.expressions.ModelLevelExpressionEvaluator; | ||
| import org.omg.sysml.lang.sysml.Element; | ||
| import org.omg.sysml.lang.sysml.Expression; | ||
| import org.omg.sysml.lang.sysml.InvocationExpression; | ||
| import org.omg.sysml.lang.sysml.Type; | ||
| import org.omg.sysml.lang.sysml.util.SysMLLibraryUtil; | ||
| import org.omg.sysml.util.EvaluationUtil; | ||
|
|
||
| public class MinimizeFunction extends ReduceFunction { | ||
| private static final String MIN_FUNCTION = "DataFunctions::min"; | ||
|
|
||
| @Override | ||
| public String getOperatorName() { | ||
| return "minimize"; | ||
| } | ||
|
|
||
| @Override | ||
| public EList<Element> invoke(InvocationExpression invocation, Element target, | ||
| ModelLevelExpressionEvaluator evaluator) { | ||
| EList<Element> list = evaluator.evaluateArgument(invocation, 0, target); | ||
| Element expr = evaluator.argumentValue(invocation, 1, target); | ||
| if (list == null || !(expr instanceof Expression)) { | ||
| return EvaluationUtil.singletonList(invocation); | ||
| } else if (list.isEmpty()) { | ||
| return EvaluationUtil.nullList(); | ||
| } else { | ||
| return reduce(invocation, list, new BiFunction<>() { | ||
| @Override | ||
| public Element apply(Element result, Element value) { | ||
| EList<Element> exprValue = evaluator.evaluateExpression((Expression)expr, target, value); | ||
| if (exprValue == null || exprValue.size() != 1) { | ||
| return null; | ||
| } else if (result == null) { | ||
| return exprValue.get(0); | ||
| } else { | ||
| Type minFunction = SysMLLibraryUtil.getLibraryType(expr, MIN_FUNCTION); | ||
| InvocationExpression minInvocation = EvaluationUtil.createInvocationOf(minFunction, result, exprValue.get(0)); | ||
| EList<Element> newResult = evaluator.evaluateInvocation(minInvocation, target); | ||
| return newResult == null || newResult.size() != 1? null: newResult.get(0); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am guessing you meant naming these
minFunction,minInvocation. Looks like a copy/paste typo, does not change behavior & result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, you are right. I've fixed it.