Explorar o código

Assert existence of Timerservice during init of state machine.

markus.muehlbrandt@itemis.de %!s(int64=14) %!d(string=hai) anos
pai
achega
3e098fa089

+ 2 - 4
examples/org.yakindu.sct.generator.java.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/TrafficLightWaitingCycleBasedStatemachine.java

@@ -99,6 +99,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 	}
 
 	public void init() {
+		assert timerService != null;
 		for (int i = 0; i < 1; i++) {
 			stateVector[i] = State.$NullState$;
 		}
@@ -120,10 +121,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 	}
 
 	public ITimerService getTimerService() {
-		if (timerService == null) {
-			throw new NullPointerException(
-					"TimerService of statemachine \"+TrafficLightWaiting+\" not set!");
-		}
+		assert timerService != null;
 		return timerService;
 	}
 

+ 1 - 2
examples/org.yakindu.sct.generator.java.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemoCycleBased.java

@@ -62,8 +62,6 @@ public class CrossingDemoCycleBased {
 		crossing.add(pl);
 		crossing.getLayoutManager().setConstraint(pl,
 				new Rectangle(50, 10, 70, 20));
-		
-		statemachine.setTimerService(new TimerService());
 
 		Thread thread = new Thread() {
 			@Override
@@ -74,6 +72,7 @@ public class CrossingDemoCycleBased {
 				// implementation of a TimerHandler. It has to implement the
 				// ITimerHandler interface.
 				statemachine.setTimerService(new TimerService());
+				statemachine.init();
 				statemachine.enter();
 				while (!isInterrupted()) {
 					statemachine.runCycle();

+ 4 - 3
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/CustomCycleBasedStatemachine.xpt

@@ -338,6 +338,9 @@ public class 
 	}
 	
 	public void init() {
+		«IF isTimedStatemachine()-»
+		assert timerService != null;
+		«ENDIF-»
 		for (int i = 0; i < «stateVector.size»; i++) {
 			stateVector[i] = State.$NullState$;
 		}
@@ -367,9 +370,7 @@ public class 
 
 	
 	public ITimerService getTimerService() {
-		if (timerService == null) {
-			throw new NullPointerException("TimerService of statemachine \"+«name»+\" not set!");
-		}
+		assert timerService != null;
 		return timerService;
 	}
 	

+ 2 - 4
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_localactions/Test_LocalActionsCycleBasedStatemachine.java

@@ -77,6 +77,7 @@ public class Test_LocalActionsCycleBasedStatemachine
 	}
 
 	public void init() {
+		assert timerService != null;
 		for (int i = 0; i < 1; i++) {
 			stateVector[i] = State.$NullState$;
 		}
@@ -98,10 +99,7 @@ public class Test_LocalActionsCycleBasedStatemachine
 	}
 
 	public ITimerService getTimerService() {
-		if (timerService == null) {
-			throw new NullPointerException(
-					"TimerService of statemachine \"+Test_LocalActions+\" not set!");
-		}
+		assert timerService != null;
 		return timerService;
 	}
 

+ 2 - 4
test-plugins/org.yakindu.sct.generator.java.runtime.test/src-gen/org/yakindu/sct/runtime/java/test_transition/Test_TransitionCycleBasedStatemachine.java

@@ -78,6 +78,7 @@ public class Test_TransitionCycleBasedStatemachine
 	}
 
 	public void init() {
+		assert timerService != null;
 		for (int i = 0; i < 1; i++) {
 			stateVector[i] = State.$NullState$;
 		}
@@ -99,10 +100,7 @@ public class Test_TransitionCycleBasedStatemachine
 	}
 
 	public ITimerService getTimerService() {
-		if (timerService == null) {
-			throw new NullPointerException(
-					"TimerService of statemachine \"+Test_Transition+\" not set!");
-		}
+		assert timerService != null;
 		return timerService;
 	}