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

Generate infrastructure to support operation calls.

markus.muehlbrandt@gmail.com 13 лет назад
Родитель
Сommit
a16a52a5d8

+ 21 - 7
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/CoreStatemachine.xpt

@@ -77,6 +77,12 @@ import java.util.List;
 	
 	private long cycleStartTime;
 	«ENDIF-»
+	
+	«FOREACH scopes.typeSelect(InternalScope) AS internal-»
+	«IF internal.hasOperations()-»
+		private «internal.getInternalOperationCallbackName()» operationCallback;
+	«ENDIF-»
+	«ENDFOREACH-»
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR Step-»
@@ -116,13 +122,13 @@ getTimerService().resetTimer(
 
 «DEFINE ActionCode FOR Execution-»
 	«getComment()-»
-	«IF AssignmentExpression.isInstance(statement)»
-	«LET statement.toCode() AS statement»
-	«statement.subString(1,statement.length-1)»;
-	«ENDLET»
-	«ELSE»
-	«statement.toCode()»;
-	«ENDIF»
+	«IF AssignmentExpression.isInstance(statement)-»
+		«LET statement.toCode() AS statement-»
+		«statement.subString(1,statement.length-1)»;
+		«ENDLET-»
+	«ELSE-»
+		«statement.toCode()»;
+	«ENDIF-»
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR Call-»
@@ -329,7 +335,15 @@ else {
 	private void set«variable.getVarName().toFirstUpper()»(«variable.type.getJavaType()» value) {
 		«variable.getVariableIdentifier()» = value;
 	}	
+	«ENDFOREACH-»
 	
+	«FOREACH scopes.typeSelect(InternalScope) AS internal-»
+	«IF internal.hasOperations()-»
+		public void set«internal.getInternalOperationCallbackName()»(
+				«internal.getInternalOperationCallbackName()» operationCallback) {
+			this.operationCallback = operationCallback;
+		}
+	«ENDIF-»
 	«ENDFOREACH-»
 «ENDDEFINE»
 

+ 12 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/ExecutionModelExtensions.ext

@@ -80,4 +80,15 @@ int getEventsCount(ExecutionFlow this):
 
 int getOffset(Scope scope):
 	JAVA org.yakindu.sct.generator.java.extensions.ExecutionModelExtensions.getOffset(org.yakindu.sct.model.sgraph.Scope);
-					
+
+boolean hasOperations(InterfaceScope this) :
+	!declarations.typeSelect(OperationDefinition).isEmpty;
+
+boolean hasOperations(InternalScope this) :
+	!declarations.typeSelect(OperationDefinition).isEmpty;
+
+getOperations(InterfaceScope this) :
+	declarations.typeSelect(OperationDefinition);
+
+getOperations(InternalScope this) :
+	declarations.typeSelect(OperationDefinition);			

+ 5 - 2
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/Expression.ext

@@ -180,9 +180,12 @@ String getOperator(RelationalOperator operator) :
 	
 String toCode(EventRaisingExpression this) :
 	if this.value != null then
-		event.getContext().toFirstLower()+"raise"+event.getEventName()+"("+value.toCode()+");"
+		event.getContext().toFirstLower()+"raise"+event.getEventName()+"("+value.toCode()+")"
 	else
-		event.getContext().toFirstLower()+"raise"+event.getEventName()+"();";
+		event.getContext().toFirstLower()+"raise"+event.getEventName()+"()";
+		
+String toCode(OperationDefinition this) :
+	"//" + getContext() + "operationCallback." + name + "()";
 		
 String getInitialValue(EventDefinition this) :
 	//if derivation != null then

+ 14 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/Naming.ext

@@ -54,6 +54,12 @@ String getInterfaceName(InterfaceScope this) :
 String getInterfaceListenerName(InterfaceScope this) :
 	getInterfaceName()+"Listener";
 
+String getInterfaceOperationCallbackName(InterfaceScope this) :
+	getInterfaceName()+"OperationCallback";
+
+String getInternalOperationCallbackName(InternalScope this) :
+	"InternalOperationCallback";
+
 String getInterfaceIdentifier(InterfaceScope this) : getInterfaceName().toFirstLower();
 	 
 String getInterfaceImplName(InterfaceScope this) :  getInterfaceName() + "Impl";
@@ -279,12 +285,19 @@ String getContext(EventDefinition this) :
 		getInterfaceIdentifier((InterfaceScope)eContainer)+"."
 	else 
 		"";
+
 String getContext(Event this) : 
 	if (InterfaceScope.isInstance(eContainer)) then  
 		getInterfaceIdentifier((InterfaceScope)eContainer)+"."
 	else 
 		"";
-		
+
+String getContext(OperationDefinition this) : 
+	if (InterfaceScope.isInstance(eContainer)) then  
+		getInterfaceIdentifier((InterfaceScope)eContainer)+"."
+	else 
+		"";
+
 String getInterfaceExtension(Scope this, GeneratorEntry entry):
 	JAVA org.yakindu.sct.generator.java.extensions.JavaExtensions.getInterfaceExtensions(org.yakindu.sct.model.sgraph.Scope, org.yakindu.sct.model.sgen.GeneratorEntry);
 

+ 32 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/StatemachineInterface.xpt

@@ -18,6 +18,15 @@ Contributors:
 «EXTENSION org::yakindu::sct::generator::java::templates::GenmodelEntries»
 «EXTENSION org::yakindu::sct::generator::java::templates::Naming»
 
+«DEFINE operationSignature FOR OperationDefinition»
+	public void «name»(«FOREACH parameters AS parameter ITERATOR iter-»
+							«IF iter.counter0 > 0-»
+								,
+							«ENDIF-»
+								«parameter.type.getJavaType()» «parameter.name»
+						«ENDFOREACH-»);
+«ENDDEFINE»
+
 «DEFINE file(sgen::GeneratorEntry entry) FOR ExecutionFlow-»
 «FILE getImplementationPackagePath(entry)+"/"+getStatemachineInterfaceName()+'.java'-»
 «getLicenseHeader(entry)»
@@ -61,6 +70,10 @@ public interface 
 		«IF createInterfaceObserverSupport(entry) && hasOutgoingEvents(interface)-»
 		public List<«interface.getInterfaceListenerName()»> getListeners();
 		«ENDIF-»
+		
+		«IF interface.hasOperations()-»
+		public void set«interface.getInterfaceOperationCallbackName()»(«interface.getInterfaceOperationCallbackName()» operationCallback);
+		«ENDIF-»
 	}
 	
 	«IF createInterfaceObserverSupport(entry) && hasOutgoingEvents(interface)-»
@@ -76,11 +89,30 @@ public interface 
 			«ENDFOREACH-»
 		}
 		«ENDIF-»
+	«IF interface.hasOperations()-»
+		public interface «interface.getInterfaceOperationCallbackName()» {
+		«FOREACH interface.getOperations() AS operation»
+			«EXPAND operationSignature FOR operation»
+		«ENDFOREACH»
+		}
+		«ENDIF-»
 	«ENDFOREACH»
 	
 	«FOREACH scopes.typeSelect(InterfaceScope) AS interface»
 	public «interface.getInterfaceName()» get«interface.getInterfaceName()»();
 	«ENDFOREACH»
+	
+	«FOREACH scopes.typeSelect(InternalScope) AS internal»
+	«IF internal.hasOperations()-»
+		public interface «internal.getInternalOperationCallbackName()» {
+			«FOREACH internal.getOperations() AS operation»
+			«EXPAND operationSignature FOR operation»
+			«ENDFOREACH»
+		}
+		
+		public void set«internal.getInternalOperationCallbackName()»(«internal.getInternalOperationCallbackName()» operationCallback);
+	«ENDIF-»
+	«ENDFOREACH»
 }
 «ENDFILE-»
 «ENDDEFINE»

+ 9 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/templates/StatemachineInterfaceImpl.xpt

@@ -27,6 +27,15 @@ private final class 
 		}
 	«ENDIF-»
 	
+	«IF hasOperations()-»
+		private «getInterfaceOperationCallbackName()» operationCallback;
+		
+		public void set«getInterfaceOperationCallbackName()»(
+				«getInterfaceOperationCallbackName()» operationCallback) {
+			this.operationCallback = operationCallback;
+		}
+	«ENDIF-»
+	
 	«FOREACH declarations.typeSelect(EventDefinition) AS event-»
 		
 		private boolean «event.getEventIdentifier()»;