Skip to content

Commit 155ad70

Browse files
eboussedvojtise
andauthored
Manage step return values (#226)
* Fix missing support of return values in steps * Make return value of a step optional * Add missing "Optional" uses for step returns Co-authored-by: Didier Vojtisek <[email protected]>
1 parent 8842c67 commit 155ad70

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.engine/src/org/eclipse/gemoc/executionframework/engine/core/AbstractCommandBasedSequentialExecutionEngine.xtend

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
66
* http://www.eclipse.org/legal/epl-v10.html
7-
*
7+
*
88
* Contributors:
99
* Inria - initial API and implementation
1010
*******************************************************************************/
11-
package org.eclipse.gemoc.executionframework.engine.core
11+
package org.eclipse.gemoc.executionframework.engine.core
1212

13+
import java.util.Arrays
14+
import java.util.concurrent.Callable
1315
import org.eclipse.emf.transaction.RecordingCommand
14-
import org.eclipse.gemoc.xdsmlframework.api.core.IRunConfiguration
1516
import org.eclipse.gemoc.xdsmlframework.api.core.IExecutionContext
16-
import java.util.Arrays
17+
import org.eclipse.gemoc.xdsmlframework.api.core.IRunConfiguration
18+
import java.util.Optional
1719

1820
abstract class AbstractCommandBasedSequentialExecutionEngine<C extends IExecutionContext<R, ?, ?>, R extends IRunConfiguration> extends AbstractSequentialExecutionEngine<C, R> {
1921

@@ -25,23 +27,28 @@ abstract class AbstractCommandBasedSequentialExecutionEngine<C extends IExecutio
2527
* @param operationName
2628
* @param operation
2729
*/
28-
protected def void executeOperation(Object caller, String className, String operationName, Runnable operation) {
30+
protected def void executeOperation(Object caller, String className, String operationName,
31+
Callable<Optional<Object>> operation) {
2932
executeOperation(caller, #{}, className, operationName, operation);
3033
}
31-
32-
protected def void executeOperation(Object caller, Object[] parameters, String className, String operationName, Runnable operation) {
34+
35+
var Optional<Object> lastResult = null
36+
37+
protected def void executeOperation(Object caller, Object[] parameters, String className, String operationName,
38+
Callable<Optional<Object>> operation) {
3339
val RecordingCommand rc = new RecordingCommand(editingDomain) {
3440
override doExecute() {
35-
operation.run()
41+
AbstractCommandBasedSequentialExecutionEngine.this.lastResult = operation.call()
3642
}
3743
}
3844
try {
3945
beforeExecutionStep(caller, className, operationName, rc, Arrays.asList(parameters))
4046
rc.execute
41-
afterExecutionStep
47+
afterExecutionStep(lastResult)
48+
lastResult = null
4249
} finally {
4350
// Important to remove notifiers.
4451
rc.dispose
4552
}
4653
}
47-
}
54+
}

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.engine/src/org/eclipse/gemoc/executionframework/engine/core/AbstractExecutionEngine.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.HashSet;
1919
import java.util.List;
2020
import java.util.Map;
21+
import java.util.Optional;
2122
import java.util.Set;
2223

2324
import org.eclipse.emf.ecore.resource.ResourceSet;
@@ -517,14 +518,17 @@ private boolean isInStep() {
517518
/**
518519
* To be called just after each execution step by an implementing engine.
519520
*/
520-
protected void afterExecutionStep() {
521+
protected void afterExecutionStep(Optional<Object> returnValue) {
521522

522523
RecordingCommand emptyrc = null;
523524

524525
try {
525526

526527
Step<?> step = currentSteps.pop();
527-
528+
if (returnValue.isPresent()) {
529+
step.getMseoccurrence().getResult().add(returnValue.get());
530+
}
531+
528532
// We commit the transaction (which might be a different one
529533
// than the one created earlier, or null if two operations
530534
// end successively)

framework/execution_framework/plugins/org.eclipse.gemoc.executionframework.engine/src/org/eclipse/gemoc/executionframework/engine/core/AbstractSequentialExecutionEngine.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
import java.io.IOException;
1414
import java.util.ArrayList;
15-
import java.util.Arrays;
1615
import java.util.Collections;
1716
import java.util.HashMap;
1817
import java.util.HashSet;
1918
import java.util.List;
2019
import java.util.Map;
20+
import java.util.Optional;
2121
import java.util.Set;
2222

2323
import org.eclipse.emf.ecore.EClass;
@@ -91,8 +91,8 @@ protected final void performStart() {
9191
}
9292

9393
@Override
94-
protected final void afterExecutionStep() {
95-
super.afterExecutionStep();
94+
protected final void afterExecutionStep(Optional<Object> returnValue) {
95+
super.afterExecutionStep(returnValue);
9696
}
9797

9898
/**
@@ -151,7 +151,6 @@ private Step<?> createStep(EObject caller, String className, String methodName,
151151
} else {
152152
result = traceAddon.getFactory().createStep(mse, args, new ArrayList<Object>());
153153
}
154-
result.getMseoccurrence().getParameters().addAll(Arrays.asList(args));
155154
return result;
156155
}
157156

0 commit comments

Comments
 (0)