Просмотр исходного кода

resolve execution slot for Operation (#1373)

* Yakindu/sctpro#643 : resolve execution slot for Operation

* JavaOperationMockup.canExecute returns false if callbacks are null
(pro test)

* #643 : provide NullOperationMockup 

* can be used in contexts operation mockups are not needed

* Yakindu/sctpro#643 : IOperationMockup to be optional
Johannes Dicks 8 лет назад
Родитель
Сommit
dbd589db5b

+ 13 - 0
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/DefaultExecutionSlotResolver.xtend

@@ -27,6 +27,7 @@ import org.yakindu.sct.model.stext.stext.InterfaceScope
 import org.yakindu.sct.simulation.core.sruntime.CompositeSlot
 import org.yakindu.sct.simulation.core.sruntime.ExecutionContext
 import org.yakindu.sct.simulation.core.sruntime.ExecutionSlot
+import org.yakindu.base.types.Operation
 
 /**
  * Default implementation for resolving execution slots based on expressions.
@@ -55,6 +56,10 @@ class DefaultExecutionSlotResolver implements IExecutionSlotResolver {
 		return context.getVariable(e.feature.fullyQualifiedName.toString)
 	}
 	
+	def dispatch ExecutionSlot resolveByFeature(ExecutionContext context, FeatureCall e, Operation feature){
+		return resolveCompositeSlot(context, e)
+	}
+	
 	def dispatch ExecutionSlot resolveByFeature(ExecutionContext context, FeatureCall e, Event feature){
 		return resolveCompositeSlot(context, e)
 	}
@@ -95,6 +100,10 @@ class DefaultExecutionSlotResolver implements IExecutionSlotResolver {
 		slot // fallback
 	}
 	
+	def protected dispatch ExecutionSlot resolveFromSlot(CompositeSlot slot, Operation call) {
+		resolveByFeature(slot, call)
+	}
+	
 	def protected dispatch ExecutionSlot resolveFromSlot(CompositeSlot slot, FeatureCall call) {
 		resolveByFeature(slot, call.feature)
 	}
@@ -107,6 +116,10 @@ class DefaultExecutionSlotResolver implements IExecutionSlotResolver {
 		resolveByName(slot, feature)
 	}
 	
+	def protected dispatch ExecutionSlot resolveByFeature(CompositeSlot slot, Operation feature) {
+		resolveByName(slot, feature)
+	}
+	
 	def protected dispatch ExecutionSlot resolveByFeature(CompositeSlot slot, Event feature) {
 		resolveByName(slot, feature)
 	}

+ 54 - 38
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/IOperationMockup.java

@@ -1,38 +1,54 @@
-/**
- * Copyright (c) 2013 committers of YAKINDU and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * Contributors:
- * 	committers of YAKINDU - initial API and implementation
- * 
- */
-package org.yakindu.sct.simulation.core.sexec.interpreter;
-
-import org.yakindu.base.types.Operation;
-
-/**
- * Called during simulation when an {@link Operation} is executed. Allows to
- * implement Mockups for operation calls.
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public interface IOperationMockup {
-	/**
-	 * Called before an operation is executed
-	 * 
-	 * @return true if the implementation provides a mockup for the given
-	 *         definition, false otherwise
-	 */
-	public boolean canExecute(Operation definition, Object[] parameter);
-
-	/**
-	 * Called when the operation is executed
-	 * 
-	 * @return the operations return value, maybe null
-	 */
-	public Object execute(Operation definition, Object[] parameter);
-	
-}
+/**
+ * Copyright (c) 2013 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.simulation.core.sexec.interpreter;
+
+import org.yakindu.base.types.Operation;
+
+/**
+ * Called during simulation when an {@link Operation} is executed. Allows to
+ * implement Mockups for operation calls.
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public interface IOperationMockup {
+	/**
+	 * Called before an operation is executed
+	 * 
+	 * @return true if the implementation provides a mockup for the given
+	 *         definition, false otherwise
+	 */
+	public boolean canExecute(Operation definition, Object[] parameter);
+
+	/**
+	 * Called when the operation is executed
+	 * 
+	 * @return the operations return value, maybe null
+	 */
+	public Object execute(Operation definition, Object[] parameter);
+	
+	/**
+	 * @author Johannes Dicks - Initial contribution and API
+	 */
+	public static final class NullOperationMock implements IOperationMockup{
+
+		@Override
+		public boolean canExecute(Operation definition, Object[] parameter) {
+			return false;
+		}
+
+		@Override
+		public Object execute(Operation definition, Object[] parameter) {
+			return null;
+		}
+	}
+	
+}

+ 1 - 1
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/StextStatementInterpreter.xtend

@@ -193,7 +193,7 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 			return (executionSlot as ExecutionEvent).raised
 
 		// reference to an element with complex type is not reflected in an execution variable but in a composite slot
-		// TODO hide reference mechanism in resolver
+		// TODO hide reference mechanism in resolver
 		if (executionSlot instanceof CompositeSlot)
 			return executionSlot