Jelajahi Sumber

Merge pull request #732 from Yakindu/issue_566_730

Fix issues 566 730
Axel Terfloth 9 tahun lalu
induk
melakukan
ff7ce120e0

+ 11 - 2
plugins/org.yakindu.sct.model.sexec/src/org/yakindu/sct/model/sexec/transformation/BehaviorMapping.xtend

@@ -51,6 +51,7 @@ import org.yakindu.sct.model.stext.stext.ReactionTrigger
 import org.yakindu.sct.model.stext.stext.RegularEventSpec
 import org.yakindu.sct.model.stext.stext.TimeEventSpec
 import org.yakindu.base.expressions.expressions.ExpressionsFactory
+import java.util.Collection
 
 class BehaviorMapping {
 
@@ -603,12 +604,20 @@ class BehaviorMapping {
 					s.addEnterStepsForTargetsToSequence(targets, seq)
 			}
 		} else {
-			//in the case only sibling regions contain targets the region must be entered using the defaut enter sequence
-			seq.steps.add(it.enterSequences.defaultSequence.newCall)
+			// in the case only sibling regions contain targets the region must be entered 
+			// using the defaut enter sequence, if this exists
+			it.enterSequences.defaultSequence?.newCall?.addTo(seq.steps)
 		}
 	}
 	
 	
+	/** TODO: move... */
+	def <T> Collection<T> addTo(T it, Collection<T> c) {
+		c.add(it);
+		c
+	}
+	
+	
 	def dispatch Set<ExecutionNode> allNodes(ExecutionRegion it) {
 		val allNodes = new HashSet<ExecutionNode>()
 		allNodes.addAll(nodes)

+ 1 - 1
plugins/org.yakindu.sct.model.sexec/src/org/yakindu/sct/model/sexec/transformation/SexecElementMapping.xtend

@@ -238,7 +238,7 @@ import org.yakindu.base.types.Event
 	} 
 
 	def Call newCall(Step step) {
-//	  if (step ==  null) throw new IllegalArgumentException("Attempt to create 'null' call.")
+		if (step ==  null) throw new IllegalArgumentException("Attempt to create 'null' call.")
 		val r = sexecFactory.createCall
 		r.step = step
 		r

+ 17 - 10
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/container/AbstractExecutionFlowSimulationEngine.java

@@ -63,14 +63,21 @@ public abstract class AbstractExecutionFlowSimulationEngine implements ISimulati
 	protected void runCycle() {
 		try {
 			interpreter.runCycle();
-		} catch (WrappedException ex) {
-			handleWrappedException(ex);
+		} catch (Exception e) {
+			handleException(e);
 		}
 	}
 
-	private void handleWrappedException(WrappedException ex) {
+	private void handleException(Exception e) {
+		if (e instanceof WrappedException) {
+			WrappedException e1 = (WrappedException)e;
+			handleException(e1.getCause().getMessage(), e1.getCause());
+		} else handleException(e.getMessage(), e);
+	}
+	
+	private void handleException(String message, Throwable t) {
 		Status errorStatus = new Status(Status.ERROR, Activator.PLUGIN_ID, ERROR_DURING_SIMULATION,
-				ex.getCause().getMessage(), ex.getCause());
+				message, t);
 		IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(errorStatus);
 		try {
 			statusHandler.handleStatus(errorStatus, getDebugTarget());
@@ -116,8 +123,8 @@ public abstract class AbstractExecutionFlowSimulationEngine implements ISimulati
 	public void start() {
 		try {
 			interpreter.enter();
-		} catch (WrappedException ex) {
-			handleWrappedException(ex);
+		} catch (Exception ex) {
+			handleException(ex);
 		}
 	}
 
@@ -130,8 +137,8 @@ public abstract class AbstractExecutionFlowSimulationEngine implements ISimulati
 		try {
 			suspended = false;
 			interpreter.resume();
-		} catch (WrappedException ex) {
-			handleWrappedException(ex);
+		} catch (Exception ex) {
+			handleException(ex);
 		}
 	}
 
@@ -145,8 +152,8 @@ public abstract class AbstractExecutionFlowSimulationEngine implements ISimulati
 			interpreter.resume();
 			interpreter.runCycle();
 			interpreter.suspend();
-		} catch (WrappedException ex) {
-			handleWrappedException(ex);
+		} catch (Exception ex) {
+			handleException(ex);
 		}
 	}
 

+ 32 - 0
test-plugins/org.yakindu.sct.model.sexec.test/pom.xml

@@ -14,6 +14,38 @@
 	<packaging>eclipse-test-plugin</packaging>
 	<build>
 		<plugins>
+		
+			<plugin>
+				<artifactId>maven-clean-plugin</artifactId>
+				<configuration>
+					<filesets>
+						<fileset>
+							<directory>xtend-gen</directory>
+							<includes>
+								<include>**</include>
+							</includes>
+							<excludes>
+								<exclude>.gitignore</exclude>
+								<exclude>.svn/</exclude>
+							</excludes>
+						</fileset>
+					</filesets>
+				</configuration>
+			</plugin>
+			
+			<plugin>
+				<groupId>org.eclipse.xtend</groupId>
+				<artifactId>xtend-maven-plugin</artifactId>
+				<executions>
+					<execution>
+						<goals>
+							<goal>compile</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+
+		
 			<plugin>
 				<groupId>org.eclipse.tycho</groupId>
 				<artifactId>tycho-surefire-plugin</artifactId>

+ 2 - 1
test-plugins/org.yakindu.sct.model.sexec.test/src/org/yakindu/sct/model/sexec/transformation/test/AllTests.java

@@ -30,7 +30,8 @@ import org.junit.runners.Suite.SuiteClasses;
 		ModelSequencerHistoryTest.class,
 		SelfTransitionTest.class,
 		StatechartEnterExistActionTest.class,
-		DefaultNamingServiceTest.class
+		DefaultNamingServiceTest.class,
+		NullCallTest.class
 		})
 public class AllTests {
 

+ 60 - 0
test-plugins/org.yakindu.sct.model.sexec.test/src/org/yakindu/sct/model/sexec/transformation/test/NullCallTest.xtend

@@ -0,0 +1,60 @@
+/** 
+ * Copyright (c) 2016 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.model.sexec.transformation.test
+
+import org.junit.Test
+import static org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory.*
+import static org.yakindu.sct.model.stext.test.util.StextTestFactory.*
+import static org.junit.Assert.*
+import org.eclipse.emf.ecore.EObject
+import org.yakindu.sct.model.sexec.Call
+
+/** 
+ * This test class tests transformation errors that create calls to null sequences. This covers the issues:
+ *  - #566
+ *  
+ * @author terfloth@itemis.de
+ */
+class NullCallTest extends ModelSequencerTest {
+	
+	
+	@Test def syncEntryOnReqionsWithoutDefaultSequence() {
+		val tsc = new SCTTestUtil.MinimalTSC()
+		
+		val s2 = _createState("S2", tsc.r)
+		
+		val s2_r1 = _createRegion("r1", s2)
+		val s2_r1_sync = _createSynchronization(s2_r1)
+		val s1_t1 = _createTransition(tsc.s1, s2_r1_sync)
+		val s1_t1_tr = _createReactionTrigger(s1_t1)
+		_createRegularEventSpec(tsc.e1, s1_t1_tr)
+		val a = _createState("A", s2_r1)
+		_createTransition(s2_r1_sync, a)
+		
+		
+		val s2_r2 = _createRegion("r2", s2)
+		val b = _createState("B", s2_r2)
+		_createTransition(s2_r1_sync, b)
+		
+		
+		val flow = sequencer.transform(tsc.sc);
+		
+		assertNoNullCalls(flow)
+		
+	}
+	
+	
+	def void assertNoNullCalls(EObject e) {
+		assertFalse (e.eAllContents.filter(Call).exists[ step == null] )
+	}
+	
+
+}

+ 8 - 0
test-plugins/org.yakindu.sct.model.sgraph.test/src/org/yakindu/sct/model/sgraph/test/util/SGraphTestFactory.java

@@ -17,6 +17,7 @@ import org.yakindu.sct.model.sgraph.Region;
 import org.yakindu.sct.model.sgraph.SGraphFactory;
 import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.sgraph.Synchronization;
 import org.yakindu.sct.model.sgraph.Transition;
 import org.yakindu.sct.model.sgraph.Vertex;
 import org.yakindu.sct.model.sgraph.impl.SGraphFactoryImpl;
@@ -73,6 +74,13 @@ public class SGraphTestFactory extends SGraphFactoryImpl {
 		return entry;
 	}
 
+	public static Synchronization _createSynchronization(Region r) {
+		Synchronization sync = SGraphFactory.eINSTANCE.createSynchronization();
+		if (r != null)
+			r.getVertices().add(sync);
+		return sync;
+	}
+
 	public static Transition _createTransition(Vertex source, Vertex target) {
 		Transition t = SGraphFactory.eINSTANCE.createTransition();
 		t.setSource(source);