summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-07-29 05:16:12 (EDT)
committer Henrik Rentz-Reichert2011-07-29 05:16:12 (EDT)
commit0077ca03996add01fa52491a81cb1eb8dc78ac02 (patch)
tree6f87b5a64ca6482b6bd9386f5f06a51d22cf89d5
parent7d66927bddff25be08ce96bcb0ea264b8d53bebe (diff)
downloadorg.eclipse.etrice-0077ca03996add01fa52491a81cb1eb8dc78ac02.zip
org.eclipse.etrice-0077ca03996add01fa52491a81cb1eb8dc78ac02.tar.gz
org.eclipse.etrice-0077ca03996add01fa52491a81cb1eb8dc78ac02.tar.bz2
[generator, generator.java] moved general extensions to target language
independent generator plug-in Change-Id: I0fa42a5ce9eb4e66557ec537b8acd49c80e5a620
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/extensions/Extensions.ext116
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/JavaGenerator.java47
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/JavaTransitionChainVisitor.java11
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/DataClass.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/DocGraphviz.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/StateMachine.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemRunner.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates_CPP/ActorClass.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates_CPP/DataClass.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates_CPP/DocGraphviz.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates_CPP/ProtocolClass.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates_CPP/StateMachine.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates_CPP/SubSystemClass.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates_CPP/SubSystemRunner.xpt1
-rw-r--r--plugins/org.eclipse.etrice.generator/.project6
-rw-r--r--plugins/org.eclipse.etrice.generator/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/Extensions.ext140
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/Extensions.java71
21 files changed, 241 insertions, 165 deletions
diff --git a/plugins/org.eclipse.etrice.generator.java/src/extensions/Extensions.ext b/plugins/org.eclipse.etrice.generator.java/src/extensions/Extensions.ext
index 45bcb75..24f1c69 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/extensions/Extensions.ext
+++ b/plugins/org.eclipse.etrice.generator.java/src/extensions/Extensions.ext
@@ -17,22 +17,12 @@
import room;
import etricegen;
+extension org::eclipse::etrice::generator::extensions::Extensions;
extension org::eclipse::xtend::util::stdlib::naming;
///////////////////////////////////////////////////////////////////////////////
// general
-// package and path for room classes
-String getPackage(RoomClass rc): ((RoomModel)rc.eRootContainer).name;
-String getPackage(ExpandedActorClass rc): ((RoomModel)rc.actorClass.eRootContainer).name;
-String getPath(RoomClass rc): getPathFromPackage(getPackage(rc));
-
-// make a valid identifier from a path string
-String getPathName(String path): path.replaceAll("/","_");
-
-private String getPathFromPackage(String packageName):
- packageName.replaceAll("\\.", "/") + "/";
-
///////////////////////////////////////////////////////////////////////////////
// types
@@ -83,112 +73,12 @@ String defaultValue(TypedID a): a.type.type!=null? "new "+a.type.type.name+"()"
///////////////////////////////////////////////////////////////////////////////
// protocol and messages
-// message lists with super class messages, super classes first
-cached List[Message] getAllIncomingMessages(ProtocolClass pc): pc.base!=null? pc.base.getAllIncomingMessages().union(pc.incomingMessages) : pc.incomingMessages;
-cached List[Message] getAllOutgoingMessages(ProtocolClass pc): pc.base!=null? pc.base.getAllOutgoingMessages().union(pc.outgoingMessages) : pc.outgoingMessages;
-List[Message] getIncoming(ProtocolClass pc, boolean conj): conj? pc.getAllOutgoingMessages():pc.getAllIncomingMessages();
-List[Message] getOutgoing(ProtocolClass pc, boolean conj): conj? pc.getAllIncomingMessages():pc.getAllOutgoingMessages();
-
-PortClass getPortClass(ProtocolClass pc, boolean conj): conj? pc.conjugate:pc.regular;
-
-boolean handlesSend(ProtocolClass pc, boolean conj): pc.getPortClass(conj)==null? false:!pc.getPortClass(conj).msgHandlers.select(e|pc.getOutgoing(conj).contains(e.msg)).isEmpty;
-boolean handlesReceive(ProtocolClass pc, boolean conj): pc.getPortClass(conj)==null? false:!pc.getPortClass(conj).msgHandlers.select(e|pc.getIncoming(conj).contains(e.msg)).isEmpty;
-List[MessageHandler] getReceiveHandlers(ProtocolClass pc, boolean conj): pc.getPortClass(conj)==null? {}:pc.getPortClass(conj).msgHandlers.select(e|pc.getIncoming(conj).contains(e.msg));
-List[MessageHandler] getSendHandlers(ProtocolClass pc, boolean conj): pc.getPortClass(conj)==null? {}:pc.getPortClass(conj).msgHandlers.select(e|pc.getOutgoing(conj).contains(e.msg));
-
-MessageHandler getSendHandler(Message m, boolean conj): ((ProtocolClass)m.eContainer).getSendHandlers(conj).selectFirst(e|e.msg==m);
-
-boolean isIncoming(Message m): ((ProtocolClass)m.eContainer).getAllIncomingMessages().contains(m);
-String getCodeName(Message m): m.isIncoming()? "IN_"+m.name:"OUT_"+m.name;
-
///////////////////////////////////////////////////////////////////////////////
-// actor structure
-
-// getting port class names from ProtocolClass, Port and ExternalPort
-String getPortClassName(ProtocolClass p, boolean conj): p.name+((conj)? "ConjPort" : "Port");
-String getPortClassName(Port p): p.multiplicity>1? getPortClassName(p.protocol, p.conjugated)+"Repl" : getPortClassName(p.protocol, p.conjugated);
-String getPortClassName(ExternalPort p): getPortClassName(p.ifport.protocol, p.ifport.conjugated);
-String getPortClassName(SAPRef sap): sap.protocol.getPortClassName(true);
-String getPortClassName(ServiceImplementation svc): svc.spp.protocol.getPortClassName(false)+"Repl";
-
-// collect internal and external end ports into one list
-// HOWTO: ac.extPorts.collect(e|e.ifport) can be abbreviated to ac.extPorts.ifport
-List[Port] getEndPorts(ActorClass ac): ac.intPorts.union(ac.extPorts.ifport);
-
-// collect also super class features (super classes first)
-//private List[Port] getAllEndPorts(ActorClass ac): ac.base!=null? ac.base.getAllEndPorts().union(ac.getEndPorts()) : ac.getEndPorts();
-//private List[Attribute] getAllAttributes(ActorClass ac): ac.base!=null? ac.base.getAllAttributes().union(ac.attributes) : ac.attributes;
-//private List[Operation] getAllOperations(ActorClass ac): ac.base!=null? ac.base.getAllOperations().union(ac.operations) : ac.operations;
-
-
-// HOWTO: polymorphic dispatching (alias method overloading) in xtend
-// state names from State sub-classes
-//private String getStateName(State state): null; // polymorphic placeholder (abstract rule)
-//private String getStateName(BaseState state): state.name;
-//private String getStateName(RefinedState state): state.base.name;
+// actor
-// Init Transition
-boolean hasInitTransition(StateGraph sg): sg.transitions.typeSelect(InitialTransition).size==1;
-Transition getInitTransition(StateGraph sg): sg.transitions.typeSelect(InitialTransition).first();
-private getTerminalFromToTransition(Transition trans): trans.to;
-getStateFromTerminal(TransitionTerminal tt): null;
-BaseState getStateFromTerminal(StateTerminal tt): tt.state;
-//getStateFromTerminal(TrPointTerminal tt): tt.trPoint;
-//getStateFromTerminal(SubStateTrPointTerminal tt): tt.state;
-//getStateFromTerminal(ChoicepointTerminal tt): tt.cp;
-BaseState getInitState(StateGraph sg) : sg.getInitTransition().getTerminalFromToTransition().getStateFromTerminal();
-
-// state lists
-boolean isLeaf(State s): s.subgraph==null;
-List[State] getLeafStateList(StateGraph sg): sg.states.collect(e|e.getLeafStateList()).flatten();
-List[State] getLeafStateList(State s): s.isLeaf()? s : s.subgraph.getLeafStateList();
-
-List[State] getStateList(StateGraph sg): sg.states.collect(e|e.getStateList()).flatten();
-List[State] getStateList(State s): s.isLeaf()? s : s.subgraph.getStateList().add(s).flatten();
-int getNumberOfInheritedStates(ActorClass ac): ac.base==null? 0:(ac.base.stateMachine.getStateList().size+ac.base.getNumberOfInheritedStates());
-List[State] getAllStates(ActorClass ac): ac.base==null? ac.stateMachine.getStateList() : ac.base.getAllStates().union(ac.stateMachine.getStateList());
-
-List[State] getBaseStateList(StateGraph sg): sg.getStateList().select(e|BaseState.isInstance(e));
-int getNumberOfInheritedBaseStates(ActorClass ac): ac.base==null? 0:(ac.base.stateMachine.getBaseStateList().size+ac.base.getNumberOfInheritedBaseStates());
-List[State] getAllBaseStates(ActorClass ac): ac.base==null? ac.stateMachine.getBaseStateList() : ac.base.getAllBaseStates().union(ac.stateMachine.getBaseStateList());
-
-
-// detail code
-boolean hasEntryCode(State s): s.entryCode.commands.size>0;
-boolean hasExitCode(State s): s.exitCode.commands.size>0;
-cached String getEntryCode(ExpandedActorClass ac, State s):
- RefinedState.isInstance(s)? "super."+s.getEntryCodeOperationName()+"();\n"+ac.getCode(s.entryCode) : ac.getCode(s.entryCode);
-cached String getExitCode(ExpandedActorClass ac, State s):
- RefinedState.isInstance(s)? ac.getCode(s.exitCode)+"super."+s.getEntryCodeOperationName()+"();\n" : ac.getCode(s.exitCode);
-boolean hasActionCode(Transition t): t.action.commands.size>0;
-boolean hasGuard(Trigger tr): tr.guard!=null && tr.guard.guard!=null && tr.guard.guard.commands.size>0;
-boolean hasGuard(ExpandedActorClass ac, ActiveTrigger at): at.transitions.triggers.exists(e|ac.isMatching(e, at.trigger) && e.hasGuard());
-cached String getActionCode(ExpandedActorClass ac, Transition t): ac.getCode(t.action);
-cached String getEntryCodeOperationName(State s): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getEntryCodeOperationName(org.eclipse.etrice.core.room.State);
-cached String getExitCodeOperationName(State s): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getExitCodeOperationName(org.eclipse.etrice.core.room.State);
-cached String getActionCodeOperationName(Transition t): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getActionCodeOperationName(org.eclipse.etrice.core.room.Transition);
-cached String getChainId(TransitionChain t): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getChainId(org.eclipse.etrice.generator.etricegen.TransitionChain);
-
-// State Name and StateID
-cached String getStatePathName(State s): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getStatePathName(org.eclipse.etrice.core.room.State);
-cached String getStateId(State s): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getStateId(org.eclipse.etrice.core.room.State);
-cached String getParentStateId(State s): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getParentStateId(org.eclipse.etrice.core.room.State);
-
-String getContextId(TransitionChain tc): tc.getStateContext().getStateId();
-String getExecuteChainCode(ExpandedActorClass ac, TransitionChain tc): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getExecuteChain(org.eclipse.etrice.generator.etricegen.ExpandedActorClass, org.eclipse.etrice.generator.etricegen.TransitionChain);
-
-// getTransitionList
-List[Transition] getTransitionList(State s): s.isLeaf()? {} : s.subgraph.getTransitionList();
-List[Transition] getTransitionList(StateGraph sg): sg.transitions.union(sg.states.getTransitionList());
-
-// transition data
-private boolean hasData(TriggeredTransition tt): !tt.triggers.msgFromIfPairs.message.select(e|e.data!=null).isEmpty;
private String getDataTypeCast(TriggeredTransition tt): tt.triggers.msgFromIfPairs.message.select(e|e.data!=null).first().data.type.typeObjectName();
private String getDataType(TriggeredTransition tt): tt.triggers.msgFromIfPairs.message.select(e|e.data!=null).first().data.type.typeName();
String getArgumentList(ExpandedActorClass xpac, Transition t): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getArgumentList(org.eclipse.etrice.generator.etricegen.ExpandedActorClass, org.eclipse.etrice.core.room.Transition);
String getTypedDataDefinition(Message m): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getTypedData(org.eclipse.etrice.core.room.Message);
-// stop Operation
-boolean overridesStop(ActorClass ac): !ac.operations.select(e|e.name=="stop"&&e.arguments.isEmpty&&e.returntype==null).isEmpty
- || (ac.base!=null && ac.base.overridesStop());
-
+String getExecuteChainCode(ExpandedActorClass ac, TransitionChain tc): JAVA org.eclipse.etrice.generator.java.JavaGenerator.getExecuteChain(org.eclipse.etrice.generator.etricegen.ExpandedActorClass, org.eclipse.etrice.generator.etricegen.TransitionChain);
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/JavaGenerator.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/JavaGenerator.java
index 9c22b55..50cc358 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/JavaGenerator.java
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/JavaGenerator.java
@@ -12,12 +12,9 @@
package org.eclipse.etrice.generator.java;
-import org.eclipse.etrice.core.naming.RoomNameProvider;
import org.eclipse.etrice.core.room.InitialTransition;
import org.eclipse.etrice.core.room.Message;
import org.eclipse.etrice.core.room.MessageFromIf;
-import org.eclipse.etrice.core.room.State;
-import org.eclipse.etrice.core.room.StateGraphNode;
import org.eclipse.etrice.core.room.Transition;
import org.eclipse.etrice.core.room.Trigger;
import org.eclipse.etrice.core.room.TriggeredTransition;
@@ -28,50 +25,6 @@ import org.eclipse.etrice.generator.etricegen.TransitionChain;
public class JavaGenerator {
- // public static interface used by Xtend
-
- public static String getActionCodeOperationName(Transition t) {
- return "action_"+RoomNameProvider.getFullPath(t);
- }
-
- public static String getEntryCodeOperationName(State s) {
- return "entry_"+getStatePathName(s);
- }
-
- public static String getExitCodeOperationName(State s) {
- return "exit_"+getStatePathName(s);
- }
-
- public static String getChainId(TransitionChain tc) {
- return "CHAIN_"+RoomNameProvider.getFullPath(tc.getTransition());
- }
-
- public static boolean isTopLevel(StateGraphNode s) {
- return !(s.eContainer().eContainer() instanceof State);
- }
-
- public static State getParentState(StateGraphNode s) {
- if (isTopLevel(s))
- return null;
- else
- return (State) s.eContainer().eContainer();
- }
-
- public static String getStatePathName(State s) {
- return RoomNameProvider.getFullPath(s);
- }
-
- public static String getStateId(State s) {
- if (s==null)
- return "STATE_"+RoomNameProvider.getStateName(s);
- else
- return "STATE_"+RoomNameProvider.getFullPath(s);
- }
-
- public static String getParentStateId(State s) {
- return getStateId(getParentState(s));
- }
-
public static String getExecuteChain(ExpandedActorClass ac, TransitionChain tc) {
JavaTransitionChainVisitor tcv = new JavaTransitionChainVisitor(ac, tc);
return tc.genExecuteChain(tcv);
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/JavaTransitionChainVisitor.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/JavaTransitionChainVisitor.java
index 7dc13df..fc41b16 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/JavaTransitionChainVisitor.java
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/JavaTransitionChainVisitor.java
@@ -22,6 +22,7 @@ import org.eclipse.etrice.core.room.TypedID;
import org.eclipse.etrice.generator.etricegen.ExpandedActorClass;
import org.eclipse.etrice.generator.etricegen.ITransitionChainVisitor;
import org.eclipse.etrice.generator.etricegen.TransitionChain;
+import org.eclipse.etrice.generator.extensions.Extensions;
public class JavaTransitionChainVisitor implements ITransitionChainVisitor {
@@ -47,19 +48,19 @@ public class JavaTransitionChainVisitor implements ITransitionChainVisitor {
public String genActionOperationCall(Transition tr) {
if (tr.getAction()!=null && !tr.getAction().getCommands().isEmpty()) {
if (tr instanceof InitialTransition)
- return JavaGenerator.getActionCodeOperationName(tr)+"();\n";
+ return Extensions.getActionCodeOperationName(tr)+"();\n";
else
- return JavaGenerator.getActionCodeOperationName(tr)+"(ifitem"+dataArg+");\n";
+ return Extensions.getActionCodeOperationName(tr)+"(ifitem"+dataArg+");\n";
}
return "";
}
public String genEntryOperationCall(State state) {
- return JavaGenerator.getEntryCodeOperationName(state)+"();\n";
+ return Extensions.getEntryCodeOperationName(state)+"();\n";
}
public String genExitOperationCall(State state) {
- return JavaGenerator.getExitCodeOperationName(state)+"();\n";
+ return Extensions.getExitCodeOperationName(state)+"();\n";
}
public String genElseIfBranch(CPBranchTransition tr, boolean isFirst) {
@@ -83,7 +84,7 @@ public class JavaTransitionChainVisitor implements ITransitionChainVisitor {
}
public String genReturnState(State state) {
- return "return " + JavaGenerator.getStateId(state) + ";";
+ return "return " + Extensions.getStateId(state) + ";";
}
public String genTypedData() {
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt
index 5d3b894..f34a753 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/DataClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/DataClass.xpt
index 75f0d20..f03ca21 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/DataClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/DataClass.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/DocGraphviz.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/DocGraphviz.xpt
index dab4d32..72b8c21 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/DocGraphviz.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/DocGraphviz.xpt
@@ -15,6 +15,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt
index 51f059d..ca05951 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/StateMachine.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/StateMachine.xpt
index 15f712e..5ff4436 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/StateMachine.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/StateMachine.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt
index edb2b94..c508f45 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemRunner.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemRunner.xpt
index e570c22..e3dce20 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemRunner.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemRunner.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/ActorClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/ActorClass.xpt
index cf7ccd9..f15f28d 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/ActorClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/ActorClass.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/DataClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/DataClass.xpt
index e58bc00..35b700b 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/DataClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/DataClass.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/DocGraphviz.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/DocGraphviz.xpt
index dab4d32..72b8c21 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/DocGraphviz.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/DocGraphviz.xpt
@@ -15,6 +15,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/ProtocolClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/ProtocolClass.xpt
index 0b1a5bf..cf24ab9 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/ProtocolClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/ProtocolClass.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/StateMachine.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/StateMachine.xpt
index 15f712e..5ff4436 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/StateMachine.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/StateMachine.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/SubSystemClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/SubSystemClass.xpt
index cb7833f..cbc6dda 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/SubSystemClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/SubSystemClass.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/SubSystemRunner.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/SubSystemRunner.xpt
index e570c22..e3dce20 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/SubSystemRunner.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates_CPP/SubSystemRunner.xpt
@@ -14,6 +14,7 @@
«IMPORT room»;
«IMPORT etricegen»;
+«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»
diff --git a/plugins/org.eclipse.etrice.generator/.project b/plugins/org.eclipse.etrice.generator/.project
index c426a34..efd28e2 100644
--- a/plugins/org.eclipse.etrice.generator/.project
+++ b/plugins/org.eclipse.etrice.generator/.project
@@ -20,9 +20,15 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.xtend.shared.ui.xtendBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.xtend.shared.ui.xtendXPandNature</nature>
</natures>
</projectDescription>
diff --git a/plugins/org.eclipse.etrice.generator/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator/META-INF/MANIFEST.MF
index fe30372..9672e2d 100644
--- a/plugins/org.eclipse.etrice.generator/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.generator/META-INF/MANIFEST.MF
@@ -27,6 +27,7 @@ Export-Package: org.eclipse.etrice.generator.builder;uses:="org.eclipse.emf.ecor
org.eclipse.etrice.generator.etricegen,
org.eclipse.emf.ecore.resource.impl,
org.eclipse.emf.common.notify",
+ org.eclipse.etrice.generator.extensions,
org.eclipse.etrice.generator.workflow;
uses:="org.eclipse.emf.ecore,
org.eclipse.etrice.generator.etricegen,
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/Extensions.ext b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/Extensions.ext
new file mode 100644
index 0000000..72c939f
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/Extensions.ext
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+/*
+ collection of convenience functions for code generation
+*/
+
+import room;
+import etricegen;
+
+extension org::eclipse::xtend::util::stdlib::naming;
+
+///////////////////////////////////////////////////////////////////////////////
+// general
+
+// package and path for room classes
+String getPackage(RoomClass rc): ((RoomModel)rc.eRootContainer).name;
+String getPackage(ExpandedActorClass rc): ((RoomModel)rc.actorClass.eRootContainer).name;
+String getPath(RoomClass rc): getPathFromPackage(getPackage(rc));
+
+// make a valid identifier from a path string
+String getPathName(String path): path.replaceAll("/","_");
+
+private String getPathFromPackage(String packageName):
+ packageName.replaceAll("\\.", "/") + "/";
+
+///////////////////////////////////////////////////////////////////////////////
+// types
+
+///////////////////////////////////////////////////////////////////////////////
+// protocol and messages
+
+// message lists with super class messages, super classes first
+cached List[Message] getAllIncomingMessages(ProtocolClass pc): pc.base!=null? pc.base.getAllIncomingMessages().union(pc.incomingMessages) : pc.incomingMessages;
+cached List[Message] getAllOutgoingMessages(ProtocolClass pc): pc.base!=null? pc.base.getAllOutgoingMessages().union(pc.outgoingMessages) : pc.outgoingMessages;
+List[Message] getIncoming(ProtocolClass pc, boolean conj): conj? pc.getAllOutgoingMessages():pc.getAllIncomingMessages();
+List[Message] getOutgoing(ProtocolClass pc, boolean conj): conj? pc.getAllIncomingMessages():pc.getAllOutgoingMessages();
+
+PortClass getPortClass(ProtocolClass pc, boolean conj): conj? pc.conjugate:pc.regular;
+
+boolean handlesSend(ProtocolClass pc, boolean conj): pc.getPortClass(conj)==null? false:!pc.getPortClass(conj).msgHandlers.select(e|pc.getOutgoing(conj).contains(e.msg)).isEmpty;
+boolean handlesReceive(ProtocolClass pc, boolean conj): pc.getPortClass(conj)==null? false:!pc.getPortClass(conj).msgHandlers.select(e|pc.getIncoming(conj).contains(e.msg)).isEmpty;
+List[MessageHandler] getReceiveHandlers(ProtocolClass pc, boolean conj): pc.getPortClass(conj)==null? {}:pc.getPortClass(conj).msgHandlers.select(e|pc.getIncoming(conj).contains(e.msg));
+List[MessageHandler] getSendHandlers(ProtocolClass pc, boolean conj): pc.getPortClass(conj)==null? {}:pc.getPortClass(conj).msgHandlers.select(e|pc.getOutgoing(conj).contains(e.msg));
+
+MessageHandler getSendHandler(Message m, boolean conj): ((ProtocolClass)m.eContainer).getSendHandlers(conj).selectFirst(e|e.msg==m);
+
+boolean isIncoming(Message m): ((ProtocolClass)m.eContainer).getAllIncomingMessages().contains(m);
+String getCodeName(Message m): m.isIncoming()? "IN_"+m.name:"OUT_"+m.name;
+
+///////////////////////////////////////////////////////////////////////////////
+// actors
+
+// collect internal and external end ports into one list
+// HOWTO: ac.extPorts.collect(e|e.ifport) can be abbreviated to ac.extPorts.ifport
+List[Port] getEndPorts(ActorClass ac): ac.intPorts.union(ac.extPorts.ifport);
+
+// getting port class names from ProtocolClass, Port and ExternalPort
+String getPortClassName(ProtocolClass p, boolean conj): p.name+((conj)? "ConjPort" : "Port");
+String getPortClassName(Port p): p.multiplicity>1? getPortClassName(p.protocol, p.conjugated)+"Repl" : getPortClassName(p.protocol, p.conjugated);
+String getPortClassName(ExternalPort p): getPortClassName(p.ifport.protocol, p.ifport.conjugated);
+String getPortClassName(SAPRef sap): sap.protocol.getPortClassName(true);
+String getPortClassName(ServiceImplementation svc): svc.spp.protocol.getPortClassName(false)+"Repl";
+
+boolean hasFlatStateMachine(ActorClass ac): JAVA org.eclipse.etrice.core.room.util.RoomHelpers.hasFlatStateMachine(org.eclipse.etrice.core.room.ActorClass);
+
+// behavior annotations
+boolean isAnnotationPresent(ActorClass ac, String name): JAVA org.eclipse.etrice.core.room.util.RoomHelpers.isAnnotationPresent(org.eclipse.etrice.core.room.ActorClass, java.lang.String);
+boolean isAttributePresent(ActorClass ac, String name, String key): JAVA org.eclipse.etrice.core.room.util.RoomHelpers.isAttributePresent(org.eclipse.etrice.core.room.ActorClass, java.lang.String, java.lang.String);
+List[KeyValue] getAttributes(ActorClass ac, String name): JAVA org.eclipse.etrice.core.room.util.RoomHelpers.isAttributePresent(org.eclipse.etrice.core.room.ActorClass, java.lang.String, java.lang.String);
+String getAttribute(ActorClass ac, String name, String key): JAVA org.eclipse.etrice.core.room.util.RoomHelpers.getAttribute(org.eclipse.etrice.core.room.ActorClass, java.lang.String, java.lang.String);
+boolean isAttributePresent(Annotation ann, String key): JAVA org.eclipse.etrice.core.room.util.RoomHelpers.isAttributePresent(org.eclipse.etrice.core.room.Annotation, java.lang.String);
+String getAttribute(Annotation ann, String key): JAVA org.eclipse.etrice.core.room.util.RoomHelpers.getAttribute(org.eclipse.etrice.core.room.Annotation, java.lang.String);
+
+// Init Transition
+boolean hasInitTransition(StateGraph sg): sg.transitions.typeSelect(InitialTransition).size==1;
+Transition getInitTransition(StateGraph sg): sg.transitions.typeSelect(InitialTransition).first();
+private getTerminalFromToTransition(Transition trans): trans.to;
+getStateFromTerminal(TransitionTerminal tt): null;
+BaseState getStateFromTerminal(StateTerminal tt): tt.state;
+BaseState getInitState(StateGraph sg) : sg.getInitTransition().getTerminalFromToTransition().getStateFromTerminal();
+
+// state lists
+boolean isLeaf(State s): s.subgraph==null;
+List[State] getLeafStateList(StateGraph sg): sg.states.collect(e|e.getLeafStateList()).flatten();
+List[State] getLeafStateList(State s): s.isLeaf()? s : s.subgraph.getLeafStateList();
+
+List[State] getStateList(StateGraph sg): sg.states.collect(e|e.getStateList()).flatten();
+List[State] getStateList(State s): s.isLeaf()? s : s.subgraph.getStateList().add(s).flatten();
+int getNumberOfInheritedStates(ActorClass ac): ac.base==null? 0:(ac.base.stateMachine.getStateList().size+ac.base.getNumberOfInheritedStates());
+List[State] getAllStates(ActorClass ac): ac.base==null? ac.stateMachine.getStateList() : ac.base.getAllStates().union(ac.stateMachine.getStateList());
+
+List[State] getBaseStateList(StateGraph sg): sg.getStateList().select(e|BaseState.isInstance(e));
+int getNumberOfInheritedBaseStates(ActorClass ac): ac.base==null? 0:(ac.base.stateMachine.getBaseStateList().size+ac.base.getNumberOfInheritedBaseStates());
+List[State] getAllBaseStates(ActorClass ac): ac.base==null? ac.stateMachine.getBaseStateList() : ac.base.getAllBaseStates().union(ac.stateMachine.getBaseStateList());
+
+
+// detail code
+boolean hasEntryCode(State s): s.entryCode.commands.size>0;
+boolean hasExitCode(State s): s.exitCode.commands.size>0;
+cached String getEntryCode(ExpandedActorClass ac, State s):
+ RefinedState.isInstance(s)? "super."+s.getEntryCodeOperationName()+"();\n"+ac.getCode(s.entryCode) : ac.getCode(s.entryCode);
+cached String getExitCode(ExpandedActorClass ac, State s):
+ RefinedState.isInstance(s)? ac.getCode(s.exitCode)+"super."+s.getEntryCodeOperationName()+"();\n" : ac.getCode(s.exitCode);
+boolean hasActionCode(Transition t): t.action.commands.size>0;
+boolean hasGuard(Trigger tr): tr.guard!=null && tr.guard.guard!=null && tr.guard.guard.commands.size>0;
+boolean hasGuard(ExpandedActorClass ac, ActiveTrigger at): at.transitions.triggers.exists(e|ac.isMatching(e, at.trigger) && e.hasGuard());
+cached String getActionCode(ExpandedActorClass ac, Transition t): ac.getCode(t.action);
+cached String getEntryCodeOperationName(State s): JAVA org.eclipse.etrice.generator.extensions.Extensions.getEntryCodeOperationName(org.eclipse.etrice.core.room.State);
+cached String getExitCodeOperationName(State s): JAVA org.eclipse.etrice.generator.extensions.Extensions.getExitCodeOperationName(org.eclipse.etrice.core.room.State);
+cached String getActionCodeOperationName(Transition t): JAVA org.eclipse.etrice.generator.extensions.Extensions.getActionCodeOperationName(org.eclipse.etrice.core.room.Transition);
+cached String getChainId(TransitionChain t): JAVA org.eclipse.etrice.generator.extensions.Extensions.getChainId(org.eclipse.etrice.generator.etricegen.TransitionChain);
+
+// State Name and StateID
+cached String getStatePathName(State s): JAVA org.eclipse.etrice.generator.extensions.Extensions.getStatePathName(org.eclipse.etrice.core.room.State);
+cached String getStateId(State s): JAVA org.eclipse.etrice.generator.extensions.Extensions.getStateId(org.eclipse.etrice.core.room.State);
+cached String getParentStateId(State s): JAVA org.eclipse.etrice.generator.extensions.Extensions.getParentStateId(org.eclipse.etrice.core.room.State);
+
+String getContextId(TransitionChain tc): tc.getStateContext().getStateId();
+
+// getTransitionList
+List[Transition] getTransitionList(State s): s.isLeaf()? {} : s.subgraph.getTransitionList();
+List[Transition] getTransitionList(StateGraph sg): sg.transitions.union(sg.states.getTransitionList());
+
+// transition data
+private boolean hasData(TriggeredTransition tt): !tt.triggers.msgFromIfPairs.message.select(e|e.data!=null).isEmpty;
+
+// stop Operation
+boolean overridesStop(ActorClass ac): !ac.operations.select(e|e.name=="stop"&&e.arguments.isEmpty&&e.returntype==null).isEmpty
+ || (ac.base!=null && ac.base.overridesStop());
+
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/Extensions.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/Extensions.java
new file mode 100644
index 0000000..2a56484
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/extensions/Extensions.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.extensions;
+
+import org.eclipse.etrice.core.naming.RoomNameProvider;
+import org.eclipse.etrice.core.room.State;
+import org.eclipse.etrice.core.room.StateGraphNode;
+import org.eclipse.etrice.core.room.Transition;
+import org.eclipse.etrice.generator.etricegen.TransitionChain;
+
+/**
+ * @author hrentz
+ *
+ */
+public class Extensions {
+
+ // public static interface used by Xtend
+
+ public static String getActionCodeOperationName(Transition t) {
+ return "action_"+RoomNameProvider.getFullPath(t);
+ }
+
+ public static String getEntryCodeOperationName(State s) {
+ return "entry_"+getStatePathName(s);
+ }
+
+ public static String getExitCodeOperationName(State s) {
+ return "exit_"+getStatePathName(s);
+ }
+
+ public static String getChainId(TransitionChain tc) {
+ return "CHAIN_"+RoomNameProvider.getFullPath(tc.getTransition());
+ }
+
+ public static boolean isTopLevel(StateGraphNode s) {
+ return !(s.eContainer().eContainer() instanceof State);
+ }
+
+ public static State getParentState(StateGraphNode s) {
+ if (isTopLevel(s))
+ return null;
+ else
+ return (State) s.eContainer().eContainer();
+ }
+
+ public static String getStatePathName(State s) {
+ return RoomNameProvider.getFullPath(s);
+ }
+
+ public static String getStateId(State s) {
+ if (s==null)
+ return "STATE_"+RoomNameProvider.getStateName(s);
+ else
+ return "STATE_"+RoomNameProvider.getFullPath(s);
+ }
+
+ public static String getParentStateId(State s) {
+ return getStateId(getParentState(s));
+ }
+
+}