Browse Source

Bugfix: Operations from interfaces not simulateable

Andreas Mülder 12 years ago
parent
commit
f4f65df9ea

+ 5 - 7
plugins/org.yakindu.sct.model.sexec.interpreter/src/org/yakindu/sct/model/sexec/interpreter/stext/StextStatementInterpreter.xtend

@@ -48,7 +48,7 @@ import org.yakindu.sct.model.stext.stext.OperationDefinition
 
 /**
  * 
- * @author andreas muelder - Initial contribution and API
+ * @author andreas muelder - Initial contribution and API 
  * @authos axel terfloth - additions
  * 
  */
@@ -222,7 +222,10 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 	}
 	
 	def dispatch execute(FeatureCall call){
-		if (call.operationCall) context.call(call.feature.name)
+		if(call.operationCall && super.operationCallback.size() > 0){
+			var parameter = call.args.map(it| execute)
+			return super.executeOperationCallback(call.feature as OperationDefinition, parameter.toArray)
+		}
 		else {
 			var fqn = call.feature.fqn
 			var variableRef = context.getVariable(fqn)
@@ -231,13 +234,8 @@ class StextStatementInterpreter extends AbstractStatementInterpreter {
 			}
 			return context.isEventRaised(fqn)
 		}
-		
-		null
 	}
 
-//    def String create qn : obj.fullyQualifiedName.toString fqn(EObject obj) {
-//    }
-
     def String fqn(EObject obj) {
     	obj.fullyQualifiedName.toString
     } 

File diff suppressed because it is too large
+ 580 - 569
plugins/org.yakindu.sct.model.sexec.interpreter/xtend-gen/org/yakindu/sct/model/sexec/interpreter/stext/StextStatementInterpreter.java


+ 11 - 6
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/debugmodel/SCTDebugTarget.java

@@ -92,14 +92,19 @@ public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget,
 
 	private void initFacadeCallbacks(IProject project) {
 		ClassLoader classLoader = new WorkspaceClassLoaderFactory()
-				.createClassLoader(project);
+				.createClassLoader(project, getClass().getClassLoader());
 		ILaunchConfiguration config = launch.getLaunchConfiguration();
 		try {
-			String clazz = config.getAttribute(OPERATION_CLASS, "");
-			if (clazz != null && clazz.trim().length() > 0) {
-				Class<?> loadClass = classLoader.loadClass(clazz);
-				facade.addCallbackObject(loadClass.newInstance());
-			}
+			String classes = config.getAttribute(OPERATION_CLASS, "");
+			String[] split = classes.split(",");
+			if (split.length > 0)
+				for (String string : split) {
+					string = string.trim();
+					if (string.length() == 0)
+						continue;
+					Class<?> loadClass = classLoader.loadClass(string);
+					facade.addCallbackObject(loadClass.newInstance());
+				}
 		} catch (CoreException e) {
 			e.printStackTrace();
 		} catch (ClassNotFoundException e) {

+ 0 - 5
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/runtime/IExecutionContext.java

@@ -145,11 +145,6 @@ public interface IExecutionContext {
 
 	public void initStateConfigurationVector(int size);
 
-	/**
-	 * Calls a declared operation
-	 */
-	public void call(String procedureId);
-
 	/**
 	 * Registeres a new {@link IExecutionContextListener}
 	 */

+ 0 - 16
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/runtime/impl/ExecutionContextImpl.java

@@ -112,12 +112,6 @@ public class ExecutionContextImpl extends AbstractExecutionContext implements
 				throw new ExecutionException("Event with name " + eventName
 						+ " is undefined!");
 			event.raise(value);
-//			ExecutionEvent eventCopy = event.getCopy();
-//			if (value != null) {
-//				eventCopy.setValue(value);
-//			}
-//			raisedEvents.add(eventCopy);
-//			notifyEventRaised(eventCopy);
 		}
 	}
 
@@ -144,13 +138,7 @@ public class ExecutionContextImpl extends AbstractExecutionContext implements
 	public boolean isEventRaised(String eventName) {
 		synchronized (raisedEvents) {
 			return getDeclaredEvent(eventName).isRaised();
-//			for (IEventSlot event : raisedEvents) {
-//				if (eventName.equals(event.getName())) {
-//					return true;
-//				}
-//			}
 		}
-//		return false;
 	}
 
 	public List<ExecutionVariable> getVariables() {
@@ -206,10 +194,6 @@ public class ExecutionContextImpl extends AbstractExecutionContext implements
 		historyStateConfig = Maps.newHashMap();
 	}
 
-	public void call(String procedureId) {
-		// TODO: Implement me
-	}
-
 	public Set<RegularState> getActiveLeafStates() {
 		Set<RegularState> vertices = new HashSet<RegularState>();
 		for (ExecutionState state : activeStateConfig) {

+ 37 - 22
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/launch/tabs/StatechartLaunchConfigurationTab.java

@@ -10,6 +10,9 @@
  */
 package org.yakindu.sct.simulation.ui.launch.tabs;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
@@ -178,6 +181,16 @@ public class StatechartLaunchConfigurationTab extends JavaLaunchTab implements
 		return SimulationImages.LAUNCHER_ICON.image();
 	}
 
+	protected Set<String> getOperationClasses() {
+		String operationClasses = this.operationClass.getText();
+		String[] split = operationClasses.split(",");
+		Set<String> result = new HashSet<String>(split.length);
+		for (String string : split) {
+			result.add(string.trim());
+		}
+		return result;
+	}
+
 	@Override
 	public boolean isValid(ILaunchConfiguration launchConfig) {
 		setMessage(null);
@@ -196,28 +209,30 @@ public class StatechartLaunchConfigurationTab extends JavaLaunchTab implements
 			setErrorMessage("Cycle Period must be a number!");
 			return false;
 		}
-		String operationClass = this.operationClass.getText();
-		if (operationClass != null && operationClass.trim().length() > 0) {
-			// check if class exists
-			IProject project = ResourcesPlugin.getWorkspace().getRoot()
-					.findMember(model).getProject();
-			ClassLoader classLoader = new WorkspaceClassLoaderFactory()
-					.createClassLoader(project);
-			try {
-				Class<?> loadClass = classLoader.loadClass(operationClass);
-				loadClass.newInstance();
-			} catch (ClassNotFoundException e) {
-				setErrorMessage("Class " + operationClass
-						+ " not found in project " + project.getName() + "!");
-				return false;
-			} catch (InstantiationException e) {
-				setErrorMessage("Could not instantiate class " + operationClass
-						+ "! (No default constructor available?) ");
-				return false;
-			} catch (IllegalAccessException e) {
-				setErrorMessage("Could not access class constructor for class"
-						+ operationClass + "!");
-				return false;
+		Set<String> operationClasses = getOperationClasses();
+		if (operationClasses.size() > 0) {
+			for (String clazz : operationClasses) {
+				// check if class exists
+				IProject project = ResourcesPlugin.getWorkspace().getRoot()
+						.findMember(model).getProject();
+				ClassLoader classLoader = new WorkspaceClassLoaderFactory()
+						.createClassLoader(project, getClass().getClassLoader());
+				try {
+					Class<?> loadClass = classLoader.loadClass(clazz);
+					loadClass.newInstance();
+				} catch (ClassNotFoundException e) {
+					setErrorMessage("Class " + clazz + " not found in project "
+							+ project.getName() + "!");
+					return false;
+				} catch (InstantiationException e) {
+					setErrorMessage("Could not instantiate class " + clazz
+							+ "! (No default constructor available?) ");
+					return false;
+				} catch (IllegalAccessException e) {
+					setErrorMessage("Could not access class constructor for class"
+							+ clazz + "!");
+					return false;
+				}
 			}
 		}
 		// check for default c'tor