瀏覽代碼

exit actions are no longer called multiple times in the case of orthogonal states ( YAKHMI-458 )

terfloth@itemis.de 13 年之前
父節點
當前提交
2c98d6c1ce

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

@@ -6,7 +6,7 @@ package org.yakindu.sct.model.sexec.transformation
  * by elements from the source statechart. 
  * 
  * @author axel terfloth
- */
+ */ 
 
 import com.google.inject.Inject
 import org.eclipse.xtext.naming.IQualifiedNameProvider

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

@@ -19,7 +19,7 @@ import org.yakindu.sct.model.sgraph.SGraphFactory
 import org.yakindu.sct.model.stext.stext.StextFactory
 import org.yakindu.sct.model.sexec.StateSwitch
 import org.yakindu.sct.model.sexec.StateCase
-
+ 
 class FlowOptimizer {
 
 	@Inject extension IQualifiedNameProvider qfnProvider

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

@@ -374,7 +374,7 @@ class ModelSequencer {
 		if (t.source != null && t.source instanceof RegularState) {
 			sequence.steps.add((t.source as RegularState).create.exitSequence.newCall)	
 		}
-
+ 
 		t.exitStates().fold(sequence, [seq, state | {
 			if (state != t.source && state != topExitState) { // since we call the exit sequence of the source state we have to exclude it's exit action here
 				if (t.source.stateVector.last == state.create.stateVector.last) {

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

@@ -19,7 +19,7 @@ import org.yakindu.sct.model.sgraph.Choice
 import org.yakindu.sct.model.stext.stext.EntryEvent
 import org.yakindu.sct.model.stext.stext.ExitEvent
 import org.yakindu.sct.model.stext.stext.ReactionTrigger
-
+ 
 class StatechartExtensions {
 	
 	

+ 373 - 0
plugins/org.yakindu.sct.model.sexec/xtend-gen/org/yakindu/sct/model/sexec/transformation/FactoryExtension.java

@@ -0,0 +1,373 @@
+package org.yakindu.sct.model.sexec.transformation;
+
+import com.google.inject.Inject;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.xtext.naming.IQualifiedNameProvider;
+import org.eclipse.xtext.naming.QualifiedName;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+import org.yakindu.sct.model.sexec.Call;
+import org.yakindu.sct.model.sexec.Check;
+import org.yakindu.sct.model.sexec.CheckRef;
+import org.yakindu.sct.model.sexec.ExecutionChoice;
+import org.yakindu.sct.model.sexec.ExecutionFlow;
+import org.yakindu.sct.model.sexec.ExecutionRegion;
+import org.yakindu.sct.model.sexec.ExecutionState;
+import org.yakindu.sct.model.sexec.ScheduleTimeEvent;
+import org.yakindu.sct.model.sexec.Sequence;
+import org.yakindu.sct.model.sexec.SexecFactory;
+import org.yakindu.sct.model.sexec.Step;
+import org.yakindu.sct.model.sexec.TimeEvent;
+import org.yakindu.sct.model.sexec.UnscheduleTimeEvent;
+import org.yakindu.sct.model.sexec.transformation.StatechartExtensions;
+import org.yakindu.sct.model.sgraph.Choice;
+import org.yakindu.sct.model.sgraph.Reaction;
+import org.yakindu.sct.model.sgraph.Region;
+import org.yakindu.sct.model.sgraph.RegularState;
+import org.yakindu.sct.model.sgraph.Scope;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.sgraph.Statement;
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.Vertex;
+import org.yakindu.sct.model.stext.stext.EventDefinition;
+import org.yakindu.sct.model.stext.stext.InterfaceScope;
+import org.yakindu.sct.model.stext.stext.InternalScope;
+import org.yakindu.sct.model.stext.stext.LocalReaction;
+import org.yakindu.sct.model.stext.stext.ReactionTrigger;
+import org.yakindu.sct.model.stext.stext.StextFactory;
+import org.yakindu.sct.model.stext.stext.VariableDefinition;
+
+@SuppressWarnings("all")
+public class FactoryExtension {
+  
+  @Inject
+  private IQualifiedNameProvider qfnProvider;
+  
+  @Inject
+  private StatechartExtensions sce;
+  
+  private final HashMap<ArrayList<?>,ExecutionFlow> _createCache_create = new HashMap<ArrayList<?>,ExecutionFlow>();
+  
+  public ExecutionFlow create(final Statechart statechart) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(statechart);
+    ExecutionFlow r;
+    synchronized (_createCache_create) {
+      if (_createCache_create.containsKey(_cacheKey)) {
+        return _createCache_create.get(_cacheKey);
+      }
+      SexecFactory _sexecFactory = this.sexecFactory();
+      ExecutionFlow _createExecutionFlow = _sexecFactory.createExecutionFlow();
+      r = _createExecutionFlow;
+      _createCache_create.put(_cacheKey, r);
+    }
+    String _name = statechart.getName();
+    r.setName(_name);
+    return r;
+  }
+  
+  private final HashMap<ArrayList<?>,InterfaceScope> _createCache_create_1 = new HashMap<ArrayList<?>,InterfaceScope>();
+  
+  protected Scope _create(final InterfaceScope scope) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(scope);
+    InterfaceScope r;
+    synchronized (_createCache_create_1) {
+      if (_createCache_create_1.containsKey(_cacheKey)) {
+        return _createCache_create_1.get(_cacheKey);
+      }
+      StextFactory _stextFactory = this.stextFactory();
+      InterfaceScope _createInterfaceScope = _stextFactory.createInterfaceScope();
+      r = _createInterfaceScope;
+      _createCache_create_1.put(_cacheKey, r);
+    }
+    String _name = scope.getName();
+    r.setName(_name);
+    return r;
+  }
+  
+  private final HashMap<ArrayList<?>,InternalScope> _createCache_create_2 = new HashMap<ArrayList<?>,InternalScope>();
+  
+  protected Scope _create(final InternalScope scope) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(scope);
+    InternalScope r;
+    synchronized (_createCache_create_2) {
+      if (_createCache_create_2.containsKey(_cacheKey)) {
+        return _createCache_create_2.get(_cacheKey);
+      }
+      StextFactory _stextFactory = this.stextFactory();
+      InternalScope _createInternalScope = _stextFactory.createInternalScope();
+      r = _createInternalScope;
+      _createCache_create_2.put(_cacheKey, r);
+    }
+    return r;
+  }
+  
+  private final HashMap<ArrayList<?>,EventDefinition> _createCache_create_3 = new HashMap<ArrayList<?>,EventDefinition>();
+  
+  public EventDefinition create(final EventDefinition event) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(event);
+    EventDefinition r;
+    synchronized (_createCache_create_3) {
+      if (_createCache_create_3.containsKey(_cacheKey)) {
+        return _createCache_create_3.get(_cacheKey);
+      }
+      EventDefinition _copy = EcoreUtil.<EventDefinition>copy(event);
+      r = _copy;
+      _createCache_create_3.put(_cacheKey, r);
+    }
+    return r;
+  }
+  
+  private final HashMap<ArrayList<?>,VariableDefinition> _createCache_create_4 = new HashMap<ArrayList<?>,VariableDefinition>();
+  
+  public VariableDefinition create(final VariableDefinition v) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(v);
+    VariableDefinition r;
+    synchronized (_createCache_create_4) {
+      if (_createCache_create_4.containsKey(_cacheKey)) {
+        return _createCache_create_4.get(_cacheKey);
+      }
+      VariableDefinition _copy = EcoreUtil.<VariableDefinition>copy(v);
+      r = _copy;
+      _createCache_create_4.put(_cacheKey, r);
+    }
+    return r;
+  }
+  
+  private final HashMap<ArrayList<?>,ExecutionState> _createCache_create_5 = new HashMap<ArrayList<?>,ExecutionState>();
+  
+  public ExecutionState create(final RegularState state) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(state);
+    ExecutionState r;
+    synchronized (_createCache_create_5) {
+      if (_createCache_create_5.containsKey(_cacheKey)) {
+        return _createCache_create_5.get(_cacheKey);
+      }
+      SexecFactory _sexecFactory = this.sexecFactory();
+      ExecutionState _createExecutionState = _sexecFactory.createExecutionState();
+      r = _createExecutionState;
+      _createCache_create_5.put(_cacheKey, r);
+    }
+    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(state, null);
+    if (_operator_notEquals) {
+      {
+        String _xifexpression = null;
+        if ((state instanceof org.yakindu.sct.model.sgraph.FinalState)) {
+          _xifexpression = "_final_";
+        } else {
+          String _name = state.getName();
+          _xifexpression = _name;
+        }
+        r.setSimpleName(_xifexpression);
+        QualifiedName _fullyQualifiedName = this.qfnProvider.getFullyQualifiedName(state);
+        String _string = _fullyQualifiedName.toString();
+        String _replaceAll = _string.replaceAll(" ", "");
+        r.setName(_replaceAll);
+        r.setSourceElement(state);
+      }
+    }
+    return r;
+  }
+  
+  private final HashMap<ArrayList<?>,ExecutionChoice> _createCache_create_6 = new HashMap<ArrayList<?>,ExecutionChoice>();
+  
+  public ExecutionChoice create(final Choice choice) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(choice);
+    ExecutionChoice r;
+    synchronized (_createCache_create_6) {
+      if (_createCache_create_6.containsKey(_cacheKey)) {
+        return _createCache_create_6.get(_cacheKey);
+      }
+      SexecFactory _sexecFactory = this.sexecFactory();
+      ExecutionChoice _createExecutionChoice = _sexecFactory.createExecutionChoice();
+      r = _createExecutionChoice;
+      _createCache_create_6.put(_cacheKey, r);
+    }
+    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(choice, null);
+    if (_operator_notEquals) {
+      {
+        Region _parentRegion = choice.getParentRegion();
+        EList<Vertex> _vertices = _parentRegion.getVertices();
+        Iterable<Choice> _filter = IterableExtensions.<Choice>filter(_vertices, org.yakindu.sct.model.sgraph.Choice.class);
+        List<Choice> _list = IterableExtensions.<Choice>toList(_filter);
+        int _indexOf = _list.indexOf(choice);
+        final int n = _indexOf;
+        String _operator_plus = StringExtensions.operator_plus("_choice", ((Integer)n));
+        String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, "_");
+        r.setSimpleName(_operator_plus_1);
+        QualifiedName _fullyQualifiedName = this.qfnProvider.getFullyQualifiedName(choice);
+        String _string = _fullyQualifiedName.toString();
+        String _replaceAll = _string.replaceAll(" ", "");
+        r.setName(_replaceAll);
+        r.setSourceElement(choice);
+        SexecFactory _sexecFactory_1 = this.sexecFactory();
+        Sequence _createSequence = _sexecFactory_1.createSequence();
+        r.setReactSequence(_createSequence);
+      }
+    }
+    return r;
+  }
+  
+  private final HashMap<ArrayList<?>,ExecutionRegion> _createCache_create_7 = new HashMap<ArrayList<?>,ExecutionRegion>();
+  
+  public ExecutionRegion create(final Region region) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(region);
+    ExecutionRegion r;
+    synchronized (_createCache_create_7) {
+      if (_createCache_create_7.containsKey(_cacheKey)) {
+        return _createCache_create_7.get(_cacheKey);
+      }
+      SexecFactory _sexecFactory = this.sexecFactory();
+      ExecutionRegion _createExecutionRegion = _sexecFactory.createExecutionRegion();
+      r = _createExecutionRegion;
+      _createCache_create_7.put(_cacheKey, r);
+    }
+    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(region, null);
+    if (_operator_notEquals) {
+      {
+        String _name = region.getName();
+        r.setName(_name);
+        r.setSourceElement(region);
+      }
+    }
+    return r;
+  }
+  
+  private final HashMap<ArrayList<?>,Check> _createCache_createCheck = new HashMap<ArrayList<?>,Check>();
+  
+  public Check createCheck(final ReactionTrigger tr) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(tr);
+    Check r;
+    synchronized (_createCache_createCheck) {
+      if (_createCache_createCheck.containsKey(_cacheKey)) {
+        return _createCache_createCheck.get(_cacheKey);
+      }
+      SexecFactory _sexecFactory = this.sexecFactory();
+      Check _createCheck = _sexecFactory.createCheck();
+      r = _createCheck;
+      _createCache_createCheck.put(_cacheKey, r);
+    }
+    Reaction _reaction = this.sce.reaction(tr);
+    String _id = this.sce.id(_reaction);
+    r.setName(_id);
+    return r;
+  }
+  
+  private final HashMap<ArrayList<?>,org.yakindu.sct.model.sexec.Reaction> _createCache_create_8 = new HashMap<ArrayList<?>,org.yakindu.sct.model.sexec.Reaction>();
+  
+  public org.yakindu.sct.model.sexec.Reaction create(final Transition tr) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(tr);
+    org.yakindu.sct.model.sexec.Reaction r;
+    synchronized (_createCache_create_8) {
+      if (_createCache_create_8.containsKey(_cacheKey)) {
+        return _createCache_create_8.get(_cacheKey);
+      }
+      SexecFactory _sexecFactory = this.sexecFactory();
+      org.yakindu.sct.model.sexec.Reaction _createReaction = _sexecFactory.createReaction();
+      r = _createReaction;
+      _createCache_create_8.put(_cacheKey, r);
+    }
+    {
+      String _id = this.sce.id(tr);
+      r.setName(_id);
+      r.setTransition(true);
+      r.setSourceElement(tr);
+    }
+    return r;
+  }
+  
+  private final HashMap<ArrayList<?>,org.yakindu.sct.model.sexec.Reaction> _createCache_create_9 = new HashMap<ArrayList<?>,org.yakindu.sct.model.sexec.Reaction>();
+  
+  public org.yakindu.sct.model.sexec.Reaction create(final LocalReaction lr) {
+    final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(lr);
+    org.yakindu.sct.model.sexec.Reaction r;
+    synchronized (_createCache_create_9) {
+      if (_createCache_create_9.containsKey(_cacheKey)) {
+        return _createCache_create_9.get(_cacheKey);
+      }
+      SexecFactory _sexecFactory = this.sexecFactory();
+      org.yakindu.sct.model.sexec.Reaction _createReaction = _sexecFactory.createReaction();
+      r = _createReaction;
+      _createCache_create_9.put(_cacheKey, r);
+    }
+    {
+      String _id = this.sce.id(lr);
+      r.setName(_id);
+      r.setTransition(false);
+    }
+    return r;
+  }
+  
+  public CheckRef newRef(final Check check) {
+    CheckRef _xblockexpression = null;
+    {
+      SexecFactory _sexecFactory = this.sexecFactory();
+      CheckRef _createCheckRef = _sexecFactory.createCheckRef();
+      final CheckRef r = _createCheckRef;
+      r.setCheck(check);
+      _xblockexpression = (r);
+    }
+    return _xblockexpression;
+  }
+  
+  public Call newCall(final Step step) {
+    Call _xblockexpression = null;
+    {
+      SexecFactory _sexecFactory = this.sexecFactory();
+      Call _createCall = _sexecFactory.createCall();
+      final Call r = _createCall;
+      r.setStep(step);
+      _xblockexpression = (r);
+    }
+    return _xblockexpression;
+  }
+  
+  public ScheduleTimeEvent newScheduleTimeEvent(final TimeEvent te, final Statement timeValue) {
+    ScheduleTimeEvent _xblockexpression = null;
+    {
+      SexecFactory _sexecFactory = this.sexecFactory();
+      ScheduleTimeEvent _createScheduleTimeEvent = _sexecFactory.createScheduleTimeEvent();
+      final ScheduleTimeEvent r = _createScheduleTimeEvent;
+      r.setTimeEvent(te);
+      r.setTimeValue(timeValue);
+      _xblockexpression = (r);
+    }
+    return _xblockexpression;
+  }
+  
+  public UnscheduleTimeEvent newUnscheduleTimeEvent(final TimeEvent te) {
+    UnscheduleTimeEvent _xblockexpression = null;
+    {
+      SexecFactory _sexecFactory = this.sexecFactory();
+      UnscheduleTimeEvent _createUnscheduleTimeEvent = _sexecFactory.createUnscheduleTimeEvent();
+      final UnscheduleTimeEvent r = _createUnscheduleTimeEvent;
+      r.setTimeEvent(te);
+      _xblockexpression = (r);
+    }
+    return _xblockexpression;
+  }
+  
+  public SexecFactory sexecFactory() {
+    return SexecFactory.eINSTANCE;
+  }
+  
+  public StextFactory stextFactory() {
+    return StextFactory.eINSTANCE;
+  }
+  
+  public Scope create(final Scope scope) {
+    if ((scope instanceof InterfaceScope)) {
+      return _create((InterfaceScope)scope);
+    } else if ((scope instanceof InternalScope)) {
+      return _create((InternalScope)scope);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        java.util.Arrays.<Object>asList(scope).toString());
+    }
+  }
+}

+ 602 - 0
plugins/org.yakindu.sct.model.sexec/xtend-gen/org/yakindu/sct/model/sexec/transformation/FlowOptimizer.java

@@ -0,0 +1,602 @@
+package org.yakindu.sct.model.sexec.transformation;
+
+import com.google.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.xtext.naming.IQualifiedNameProvider;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ListExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+import org.yakindu.sct.model.sexec.Call;
+import org.yakindu.sct.model.sexec.Check;
+import org.yakindu.sct.model.sexec.CheckRef;
+import org.yakindu.sct.model.sexec.ExecutionFlow;
+import org.yakindu.sct.model.sexec.ExecutionNode;
+import org.yakindu.sct.model.sexec.ExecutionState;
+import org.yakindu.sct.model.sexec.If;
+import org.yakindu.sct.model.sexec.Reaction;
+import org.yakindu.sct.model.sexec.Sequence;
+import org.yakindu.sct.model.sexec.SexecFactory;
+import org.yakindu.sct.model.sexec.StateCase;
+import org.yakindu.sct.model.sexec.StateSwitch;
+import org.yakindu.sct.model.sexec.Step;
+import org.yakindu.sct.model.sexec.transformation.FactoryExtension;
+import org.yakindu.sct.model.sgraph.SGraphFactory;
+import org.yakindu.sct.model.stext.stext.StextFactory;
+
+@SuppressWarnings("all")
+public class FlowOptimizer {
+  
+  @Inject
+  private IQualifiedNameProvider qfnProvider;
+  
+  @Inject
+  private FactoryExtension factory;
+  
+  private boolean _inlineReactions;
+  
+  public boolean inlineReactions(final boolean b) {
+    boolean __inlineReactions = this._inlineReactions = b;
+    return __inlineReactions;
+  }
+  
+  private boolean _inlineEntryActions;
+  
+  public boolean inlineEntryActions(final boolean b) {
+    boolean __inlineEntryActions = this._inlineEntryActions = b;
+    return __inlineEntryActions;
+  }
+  
+  private boolean _inlineExitActions;
+  
+  public boolean inlineExitActions(final boolean b) {
+    boolean __inlineExitActions = this._inlineExitActions = b;
+    return __inlineExitActions;
+  }
+  
+  private boolean _inlineEnterSequences;
+  
+  public boolean inlineEnterSequences(final boolean b) {
+    boolean __inlineEnterSequences = this._inlineEnterSequences = b;
+    return __inlineEnterSequences;
+  }
+  
+  private boolean _inlineExitSequences;
+  
+  public boolean inlineExitSequences(final boolean b) {
+    boolean __inlineExitSequences = this._inlineExitSequences = b;
+    return __inlineExitSequences;
+  }
+  
+  private boolean _inlineChoices;
+  
+  public boolean inlineChoices(final boolean b) {
+    boolean __inlineChoices = this._inlineChoices = b;
+    return __inlineChoices;
+  }
+  
+  public ExecutionFlow transform(final ExecutionFlow flow) {
+    ExecutionFlow _xblockexpression = null;
+    {
+      if (this._inlineReactions) {
+        {
+          this.inlineReactionChecks(flow);
+          this.inlineReactionEffects(flow);
+        }
+      }
+      if (this._inlineEntryActions) {
+        EList<ExecutionState> _states = flow.getStates();
+        final Function1<ExecutionState,Step> _function = new Function1<ExecutionState,Step>() {
+            public Step apply(final ExecutionState state) {
+              Step _entryAction = state.getEntryAction();
+              Step _inline = FlowOptimizer.this.inline(_entryAction);
+              return _inline;
+            }
+          };
+        IterableExtensions.<ExecutionState>forEach(_states, _function);
+      }
+      if (this._inlineExitActions) {
+        EList<ExecutionState> _states_1 = flow.getStates();
+        final Function1<ExecutionState,Step> _function_1 = new Function1<ExecutionState,Step>() {
+            public Step apply(final ExecutionState state_1) {
+              Step _exitAction = state_1.getExitAction();
+              Step _inline_1 = FlowOptimizer.this.inline(_exitAction);
+              return _inline_1;
+            }
+          };
+        IterableExtensions.<ExecutionState>forEach(_states_1, _function_1);
+      }
+      if (this._inlineEnterSequences) {
+        EList<ExecutionState> _states_2 = flow.getStates();
+        final Function1<ExecutionState,Step> _function_2 = new Function1<ExecutionState,Step>() {
+            public Step apply(final ExecutionState state_2) {
+              Sequence _enterSequence = state_2.getEnterSequence();
+              Step _inline_2 = FlowOptimizer.this.inline(_enterSequence);
+              return _inline_2;
+            }
+          };
+        IterableExtensions.<ExecutionState>forEach(_states_2, _function_2);
+      }
+      if (this._inlineExitSequences) {
+        EList<ExecutionState> _states_3 = flow.getStates();
+        final Function1<ExecutionState,Step> _function_3 = new Function1<ExecutionState,Step>() {
+            public Step apply(final ExecutionState state_3) {
+              Sequence _exitSequence = state_3.getExitSequence();
+              Step _inline_3 = FlowOptimizer.this.inline(_exitSequence);
+              return _inline_3;
+            }
+          };
+        IterableExtensions.<ExecutionState>forEach(_states_3, _function_3);
+      }
+      if (this._inlineChoices) {
+        {
+          EList<ExecutionNode> _nodes = flow.getNodes();
+          final Function1<ExecutionNode,ExecutionNode> _function_4 = new Function1<ExecutionNode,ExecutionNode>() {
+              public ExecutionNode apply(final ExecutionNode node) {
+                ExecutionNode _xblockexpression_1 = null;
+                {
+                  EList<Reaction> _reactions = node.getReactions();
+                  final Function1<Reaction,Step> _function_5 = new Function1<Reaction,Step>() {
+                      public Step apply(final Reaction r) {
+                        Step _xblockexpression_2 = null;
+                        {
+                          Check _check = r.getCheck();
+                          FlowOptimizer.this.inline(_check);
+                          Step _effect = r.getEffect();
+                          Step _inline_4 = FlowOptimizer.this.inline(_effect);
+                          _xblockexpression_2 = (_inline_4);
+                        }
+                        return _xblockexpression_2;
+                      }
+                    };
+                  IterableExtensions.<Reaction>forEach(_reactions, _function_5);
+                  _xblockexpression_1 = (node);
+                }
+                return _xblockexpression_1;
+              }
+            };
+          IterableExtensions.<ExecutionNode>forEach(_nodes, _function_4);
+          EList<ExecutionNode> _nodes_1 = flow.getNodes();
+          final Function1<ExecutionNode,Step> _function_6 = new Function1<ExecutionNode,Step>() {
+              public Step apply(final ExecutionNode node_1) {
+                Sequence _reactSequence = node_1.getReactSequence();
+                Step _inline_5 = FlowOptimizer.this.inline(_reactSequence);
+                return _inline_5;
+              }
+            };
+          IterableExtensions.<ExecutionNode>forEach(_nodes_1, _function_6);
+        }
+      }
+      _xblockexpression = (flow);
+    }
+    return _xblockexpression;
+  }
+  
+  public void inlineReactionChecks(final ExecutionFlow flow) {
+    EList<ExecutionState> _states = flow.getStates();
+    final Function1<ExecutionState,ExecutionState> _function = new Function1<ExecutionState,ExecutionState>() {
+        public ExecutionState apply(final ExecutionState state) {
+          ExecutionState _inlineReactionChecks = FlowOptimizer.this.inlineReactionChecks(state);
+          return _inlineReactionChecks;
+        }
+      };
+    IterableExtensions.<ExecutionState>forEach(_states, _function);
+  }
+  
+  public ExecutionState inlineReactionChecks(final ExecutionState state) {
+    ExecutionState _xblockexpression = null;
+    {
+      EList<Reaction> _reactions = state.getReactions();
+      final Function1<Reaction,Check> _function = new Function1<Reaction,Check>() {
+          public Check apply(final Reaction r) {
+            Check _check = r.getCheck();
+            return _check;
+          }
+        };
+      List<Check> _map = ListExtensions.<Reaction, Check>map(_reactions, _function);
+      List<Check> _list = IterableExtensions.<Check>toList(_map);
+      final List<Check> checks = _list;
+      final Function1<Check,Check> _function_1 = new Function1<Check,Check>() {
+          public Check apply(final Check c) {
+            Check _inline = FlowOptimizer.this.inline(c);
+            return _inline;
+          }
+        };
+      IterableExtensions.<Check>forEach(checks, _function_1);
+      _xblockexpression = (state);
+    }
+    return _xblockexpression;
+  }
+  
+  public Check inline(final Check c) {
+    Check _xblockexpression = null;
+    {
+      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(c, null);
+      if (_operator_notEquals) {
+        {
+          ArrayList<CheckRef> _arrayList = new ArrayList<CheckRef>();
+          final List<CheckRef> cRefs = _arrayList;
+          EList<CheckRef> _refs = c.getRefs();
+          cRefs.addAll(_refs);
+          for (CheckRef ref : cRefs) {
+            {
+              Check _copy = EcoreUtil.<Check>copy(c);
+              final Check clone = _copy;
+              EObject _eContainer = ref.eContainer();
+              this.substitute(_eContainer, ref, clone);
+              ref.setCheck(null);
+            }
+          }
+        }
+      }
+      _xblockexpression = (c);
+    }
+    return _xblockexpression;
+  }
+  
+  protected Object _substitute(final EObject owner, final Check pre, final Check post) {
+    return null;
+  }
+  
+  protected Object _substitute(final If owner, final Check pre, final Check post) {
+    Object _xifexpression = null;
+    Check _check = owner.getCheck();
+    boolean _operator_equals = ObjectExtensions.operator_equals(_check, pre);
+    if (_operator_equals) {
+      owner.setCheck(post);
+    }
+    return _xifexpression;
+  }
+  
+  public void inlineReactionEffects(final ExecutionFlow flow) {
+    EList<ExecutionState> _states = flow.getStates();
+    final Function1<ExecutionState,ExecutionState> _function = new Function1<ExecutionState,ExecutionState>() {
+        public ExecutionState apply(final ExecutionState state) {
+          ExecutionState _inlineReactionEffects = FlowOptimizer.this.inlineReactionEffects(state);
+          return _inlineReactionEffects;
+        }
+      };
+    IterableExtensions.<ExecutionState>forEach(_states, _function);
+  }
+  
+  public ExecutionState inlineReactionEffects(final ExecutionState state) {
+    ExecutionState _xblockexpression = null;
+    {
+      EList<Reaction> _reactions = state.getReactions();
+      final Function1<Reaction,Step> _function = new Function1<Reaction,Step>() {
+          public Step apply(final Reaction r) {
+            Step _effect = r.getEffect();
+            return _effect;
+          }
+        };
+      List<Step> _map = ListExtensions.<Reaction, Step>map(_reactions, _function);
+      List<Step> _list = IterableExtensions.<Step>toList(_map);
+      final List<Step> effects = _list;
+      final Function1<Step,Step> _function_1 = new Function1<Step,Step>() {
+          public Step apply(final Step e) {
+            Step _inline = FlowOptimizer.this.inline(e);
+            return _inline;
+          }
+        };
+      IterableExtensions.<Step>forEach(effects, _function_1);
+      _xblockexpression = (state);
+    }
+    return _xblockexpression;
+  }
+  
+  public void inlineEntryAndExitActions(final ExecutionFlow flow) {
+    {
+      EList<ExecutionState> _states = flow.getStates();
+      final Function1<ExecutionState,Step> _function = new Function1<ExecutionState,Step>() {
+          public Step apply(final ExecutionState state) {
+            Step _entryAction = state.getEntryAction();
+            Step _inline = FlowOptimizer.this.inline(_entryAction);
+            return _inline;
+          }
+        };
+      IterableExtensions.<ExecutionState>forEach(_states, _function);
+      EList<ExecutionState> _states_1 = flow.getStates();
+      final Function1<ExecutionState,Step> _function_1 = new Function1<ExecutionState,Step>() {
+          public Step apply(final ExecutionState state_1) {
+            Step _exitAction = state_1.getExitAction();
+            Step _inline_1 = FlowOptimizer.this.inline(_exitAction);
+            return _inline_1;
+          }
+        };
+      IterableExtensions.<ExecutionState>forEach(_states_1, _function_1);
+    }
+  }
+  
+  public Step inline(final Step step) {
+    Step _xblockexpression = null;
+    {
+      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(step, null);
+      if (_operator_notEquals) {
+        {
+          ArrayList<Call> _arrayList = new ArrayList<Call>();
+          final List<Call> calls = _arrayList;
+          EList<Call> _caller = step.getCaller();
+          calls.addAll(_caller);
+          for (Call caller : calls) {
+            {
+              Step _stepCopy = this.stepCopy(step);
+              final Step clone = _stepCopy;
+              EObject _eContainer = caller.eContainer();
+              boolean _substituteCall = this.substituteCall(_eContainer, caller, clone);
+              if (_substituteCall) {
+                caller.setStep(null);
+              } else {
+                String _operator_plus = StringExtensions.operator_plus("Did not substitute \'", step);
+                String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, "\'.");
+                System.out.println(_operator_plus_1);
+              }
+            }
+          }
+        }
+      }
+      _xblockexpression = (step);
+    }
+    return _xblockexpression;
+  }
+  
+  protected boolean _substituteCall(final EObject owner, final Call pre, final Step post) {
+    return false;
+  }
+  
+  protected boolean _substituteCall(final Sequence owner, final Call call, final Step step) {
+    {
+      EList<Step> _steps = owner.getSteps();
+      boolean _contains = _steps.contains(call);
+      if (_contains) {
+        {
+          EList<Step> _steps_1 = owner.getSteps();
+          EList<Step> _steps_2 = owner.getSteps();
+          int _indexOf = _steps_2.indexOf(call);
+          _steps_1.set(_indexOf, step);
+          return true;
+        }
+      }
+      return false;
+    }
+  }
+  
+  protected boolean _substituteCall(final If owner, final Call call, final Step step) {
+    {
+      Step _thenStep = owner.getThenStep();
+      boolean _operator_equals = ObjectExtensions.operator_equals(_thenStep, call);
+      if (_operator_equals) {
+        {
+          owner.setThenStep(step);
+          return true;
+        }
+      } else {
+        Step _elseStep = owner.getElseStep();
+        boolean _operator_equals_1 = ObjectExtensions.operator_equals(_elseStep, call);
+        if (_operator_equals_1) {
+          {
+            owner.setElseStep(step);
+            return true;
+          }
+        }
+      }
+      return false;
+    }
+  }
+  
+  protected Step _stepCopy(final Step step) {
+    Step _copy = EcoreUtil.<Step>copy(step);
+    return _copy;
+  }
+  
+  protected Step _stepCopy(final Sequence seq) {
+    Sequence _xblockexpression = null;
+    {
+      SexecFactory _sexecFactory = this.sexecFactory();
+      Sequence _createSequence = _sexecFactory.createSequence();
+      final Sequence _copy = _createSequence;
+      String _name = seq.getName();
+      _copy.setName(_name);
+      String _comment = seq.getComment();
+      _copy.setComment(_comment);
+      EList<Step> _steps = _copy.getSteps();
+      EList<Step> _steps_1 = seq.getSteps();
+      final Function1<Step,Step> _function = new Function1<Step,Step>() {
+          public Step apply(final Step s) {
+            Step _stepCopy = FlowOptimizer.this.stepCopy(s);
+            return _stepCopy;
+          }
+        };
+      List<Step> _map = ListExtensions.<Step, Step>map(_steps_1, _function);
+      _steps.addAll(_map);
+      _xblockexpression = (_copy);
+    }
+    return _xblockexpression;
+  }
+  
+  protected Step _stepCopy(final If _if) {
+    If _xblockexpression = null;
+    {
+      SexecFactory _sexecFactory = this.sexecFactory();
+      If _createIf = _sexecFactory.createIf();
+      final If _copy = _createIf;
+      String _name = _if.getName();
+      _copy.setName(_name);
+      String _comment = _if.getComment();
+      _copy.setComment(_comment);
+      Check _check = _if.getCheck();
+      Step _stepCopy = this.stepCopy(_check);
+      _copy.setCheck(((Check) _stepCopy));
+      Step _xifexpression = null;
+      Step _thenStep = _if.getThenStep();
+      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_thenStep, null);
+      if (_operator_notEquals) {
+        Step _thenStep_1 = _if.getThenStep();
+        Step _stepCopy_1 = this.stepCopy(_thenStep_1);
+        _xifexpression = _stepCopy_1;
+      } else {
+        _xifexpression = null;
+      }
+      _copy.setThenStep(_xifexpression);
+      Step _xifexpression_1 = null;
+      Step _elseStep = _if.getElseStep();
+      boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_elseStep, null);
+      if (_operator_notEquals_1) {
+        Step _elseStep_1 = _if.getElseStep();
+        Step _stepCopy_2 = this.stepCopy(_elseStep_1);
+        _xifexpression_1 = _stepCopy_2;
+      } else {
+        _xifexpression_1 = null;
+      }
+      _copy.setElseStep(_xifexpression_1);
+      _xblockexpression = (_copy);
+    }
+    return _xblockexpression;
+  }
+  
+  protected Step _stepCopy(final Call call) {
+    Call _xblockexpression = null;
+    {
+      SexecFactory _sexecFactory = this.sexecFactory();
+      Call _createCall = _sexecFactory.createCall();
+      final Call _copy = _createCall;
+      String _name = call.getName();
+      _copy.setName(_name);
+      String _comment = call.getComment();
+      _copy.setComment(_comment);
+      Step _step = call.getStep();
+      _copy.setStep(_step);
+      _xblockexpression = (_copy);
+    }
+    return _xblockexpression;
+  }
+  
+  protected Step _stepCopy(final CheckRef cref) {
+    CheckRef _xblockexpression = null;
+    {
+      SexecFactory _sexecFactory = this.sexecFactory();
+      CheckRef _createCheckRef = _sexecFactory.createCheckRef();
+      final CheckRef _copy = _createCheckRef;
+      String _name = cref.getName();
+      _copy.setName(_name);
+      String _comment = cref.getComment();
+      _copy.setComment(_comment);
+      Check _check = cref.getCheck();
+      _copy.setCheck(_check);
+      _xblockexpression = (_copy);
+    }
+    return _xblockexpression;
+  }
+  
+  protected Step _stepCopy(final StateSwitch _switch) {
+    StateSwitch _xblockexpression = null;
+    {
+      SexecFactory _sexecFactory = this.sexecFactory();
+      StateSwitch _createStateSwitch = _sexecFactory.createStateSwitch();
+      final StateSwitch _copy = _createStateSwitch;
+      String _name = _switch.getName();
+      _copy.setName(_name);
+      String _comment = _switch.getComment();
+      _copy.setComment(_comment);
+      int _stateConfigurationIdx = _switch.getStateConfigurationIdx();
+      _copy.setStateConfigurationIdx(_stateConfigurationIdx);
+      EList<StateCase> _cases = _copy.getCases();
+      EList<StateCase> _cases_1 = _switch.getCases();
+      final Function1<StateCase,StateCase> _function = new Function1<StateCase,StateCase>() {
+          public StateCase apply(final StateCase c) {
+            StateCase _stepCopy = FlowOptimizer.this.stepCopy(c);
+            return _stepCopy;
+          }
+        };
+      List<StateCase> _map = ListExtensions.<StateCase, StateCase>map(_cases_1, _function);
+      _cases.addAll(_map);
+      _xblockexpression = (_copy);
+    }
+    return _xblockexpression;
+  }
+  
+  public StateCase stepCopy(final StateCase _case) {
+    StateCase _xblockexpression = null;
+    {
+      SexecFactory _sexecFactory = this.sexecFactory();
+      StateCase _createStateCase = _sexecFactory.createStateCase();
+      final StateCase _copy = _createStateCase;
+      ExecutionState _state = _case.getState();
+      _copy.setState(_state);
+      Step _step = _case.getStep();
+      Step _stepCopy = this.stepCopy(_step);
+      _copy.setStep(_stepCopy);
+      _xblockexpression = (_copy);
+    }
+    return _xblockexpression;
+  }
+  
+  public SexecFactory sexecFactory() {
+    return SexecFactory.eINSTANCE;
+  }
+  
+  public SGraphFactory sgraphFactory() {
+    return SGraphFactory.eINSTANCE;
+  }
+  
+  public StextFactory stextFactory() {
+    return StextFactory.eINSTANCE;
+  }
+  
+  public Object substitute(final EObject owner, final Check pre, final Check post) {
+    if ((owner instanceof If)
+         && (pre instanceof Check)
+         && (post instanceof Check)) {
+      return _substitute((If)owner, (Check)pre, (Check)post);
+    } else if ((owner instanceof EObject)
+         && (pre instanceof Check)
+         && (post instanceof Check)) {
+      return _substitute((EObject)owner, (Check)pre, (Check)post);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        java.util.Arrays.<Object>asList(owner, pre, post).toString());
+    }
+  }
+  
+  public boolean substituteCall(final EObject owner, final Call call, final Step step) {
+    if ((owner instanceof If)
+         && (call instanceof Call)
+         && (step instanceof Step)) {
+      return _substituteCall((If)owner, (Call)call, (Step)step);
+    } else if ((owner instanceof Sequence)
+         && (call instanceof Call)
+         && (step instanceof Step)) {
+      return _substituteCall((Sequence)owner, (Call)call, (Step)step);
+    } else if ((owner instanceof EObject)
+         && (call instanceof Call)
+         && (step instanceof Step)) {
+      return _substituteCall((EObject)owner, (Call)call, (Step)step);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        java.util.Arrays.<Object>asList(owner, call, step).toString());
+    }
+  }
+  
+  public Step stepCopy(final Step cref) {
+    if ((cref instanceof CheckRef)) {
+      return _stepCopy((CheckRef)cref);
+    } else if ((cref instanceof Call)) {
+      return _stepCopy((Call)cref);
+    } else if ((cref instanceof If)) {
+      return _stepCopy((If)cref);
+    } else if ((cref instanceof Sequence)) {
+      return _stepCopy((Sequence)cref);
+    } else if ((cref instanceof StateSwitch)) {
+      return _stepCopy((StateSwitch)cref);
+    } else if ((cref instanceof Step)) {
+      return _stepCopy((Step)cref);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        java.util.Arrays.<Object>asList(cref).toString());
+    }
+  }
+}

文件差異過大導致無法顯示
+ 2691 - 0
plugins/org.yakindu.sct.model.sexec/xtend-gen/org/yakindu/sct/model/sexec/transformation/ModelSequencer.java


+ 362 - 0
plugins/org.yakindu.sct.model.sexec/xtend-gen/org/yakindu/sct/model/sexec/transformation/StatechartExtensions.java

@@ -0,0 +1,362 @@
+package org.yakindu.sct.model.sexec.transformation;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.xtext.EcoreUtil2;
+import org.eclipse.xtext.xbase.lib.ComparableExtensions;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.Functions.Function2;
+import org.eclipse.xtext.xbase.lib.IntegerExtensions;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+import org.yakindu.sct.model.sgraph.Choice;
+import org.yakindu.sct.model.sgraph.Reaction;
+import org.yakindu.sct.model.sgraph.ReactiveElement;
+import org.yakindu.sct.model.sgraph.Region;
+import org.yakindu.sct.model.sgraph.RegularState;
+import org.yakindu.sct.model.sgraph.Scope;
+import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.Trigger;
+import org.yakindu.sct.model.sgraph.Vertex;
+import org.yakindu.sct.model.stext.stext.EventSpec;
+import org.yakindu.sct.model.stext.stext.LocalReaction;
+import org.yakindu.sct.model.stext.stext.ReactionTrigger;
+import org.yakindu.sct.model.stext.stext.TimeEventSpec;
+
+@SuppressWarnings("all")
+public class StatechartExtensions {
+  
+  public int maxOrthogonality(final Statechart sc) {
+    EList<Region> _regions = sc.getRegions();
+    final Function2<Integer,Region,Integer> _function = new Function2<Integer,Region,Integer>() {
+        public Integer apply(final Integer o , final Region r) {
+          int _maxOrthogonality = StatechartExtensions.this.maxOrthogonality(r);
+          int _operator_plus = IntegerExtensions.operator_plus(((Integer)_maxOrthogonality), o);
+          return ((Integer)_operator_plus);
+        }
+      };
+    Integer _fold = IterableExtensions.<Region, Integer>fold(_regions, ((Integer)0), _function);
+    return _fold;
+  }
+  
+  public int maxOrthogonality(final Region r) {
+    EList<Vertex> _vertices = r.getVertices();
+    final Function2<Integer,Vertex,Integer> _function = new Function2<Integer,Vertex,Integer>() {
+        public Integer apply(final Integer s , final Vertex v) {
+          int _xblockexpression = (int) 0;
+          {
+            int _maxOrthogonality = StatechartExtensions.this.maxOrthogonality(v);
+            final int mo = _maxOrthogonality;
+            int _xifexpression = (int) 0;
+            boolean _operator_greaterThan = ComparableExtensions.<Integer>operator_greaterThan(((Integer)mo), s);
+            if (_operator_greaterThan) {
+              _xifexpression = mo;
+            } else {
+              _xifexpression = s;
+            }
+            _xblockexpression = (_xifexpression);
+          }
+          return ((Integer)_xblockexpression);
+        }
+      };
+    Integer _fold = IterableExtensions.<Vertex, Integer>fold(_vertices, ((Integer)0), _function);
+    return _fold;
+  }
+  
+  protected int _maxOrthogonality(final Vertex v) {
+    return 0;
+  }
+  
+  protected int _maxOrthogonality(final State s) {
+    Integer _xifexpression = null;
+    EList<Region> _regions = s.getRegions();
+    int _size = _regions.size();
+    boolean _operator_greaterThan = ComparableExtensions.<Integer>operator_greaterThan(((Integer)_size), ((Integer)0));
+    if (_operator_greaterThan) {
+      EList<Region> _regions_1 = s.getRegions();
+      final Function2<Integer,Region,Integer> _function = new Function2<Integer,Region,Integer>() {
+          public Integer apply(final Integer o , final Region r) {
+            int _maxOrthogonality = StatechartExtensions.this.maxOrthogonality(r);
+            int _operator_plus = IntegerExtensions.operator_plus(((Integer)_maxOrthogonality), o);
+            return ((Integer)_operator_plus);
+          }
+        };
+      Integer _fold = IterableExtensions.<Region, Integer>fold(_regions_1, ((Integer)0), _function);
+      _xifexpression = _fold;
+    } else {
+      _xifexpression = 1;
+    }
+    return _xifexpression;
+  }
+  
+  public Reaction reaction(final Trigger tr) {
+    EObject _eContainer = tr.eContainer();
+    return ((Reaction) _eContainer);
+  }
+  
+  public Statechart statechart(final State state) {
+    Region _parentRegion = state.getParentRegion();
+    Statechart _statechart = this.statechart(_parentRegion);
+    return _statechart;
+  }
+  
+  public Statechart statechart(final Region region) {
+    Statechart _xifexpression = null;
+    EObject _eContainer = region.eContainer();
+    if ((_eContainer instanceof org.yakindu.sct.model.sgraph.Statechart)) {
+      EObject _eContainer_1 = region.eContainer();
+      _xifexpression = ((Statechart) _eContainer_1);
+    } else {
+      EObject _eContainer_2 = region.eContainer();
+      Statechart _statechart = this.statechart(((State) _eContainer_2));
+      _xifexpression = _statechart;
+    }
+    return _xifexpression;
+  }
+  
+  public List<TimeEventSpec> timeEventSpecs(final State state) {
+    {
+      ArrayList<TimeEventSpec> _arrayList = new ArrayList<TimeEventSpec>();
+      ArrayList<TimeEventSpec> tesList = _arrayList;
+      EList<Transition> _outgoingTransitions = state.getOutgoingTransitions();
+      final Function2<ArrayList<TimeEventSpec>,Transition,ArrayList<TimeEventSpec>> _function = new Function2<ArrayList<TimeEventSpec>,Transition,ArrayList<TimeEventSpec>>() {
+          public ArrayList<TimeEventSpec> apply(final ArrayList<TimeEventSpec> s , final Transition r) {
+            ArrayList<TimeEventSpec> _xblockexpression = null;
+            {
+              List<EObject> _eAllContentsAsList = EcoreUtil2.eAllContentsAsList(r);
+              Iterable<TimeEventSpec> _filter = IterableExtensions.<TimeEventSpec>filter(_eAllContentsAsList, org.yakindu.sct.model.stext.stext.TimeEventSpec.class);
+              final Function1<TimeEventSpec,Boolean> _function_1 = new Function1<TimeEventSpec,Boolean>() {
+                  public Boolean apply(final TimeEventSpec tes) {
+                    boolean _add = s.add(tes);
+                    return ((Boolean)_add);
+                  }
+                };
+              IterableExtensions.<TimeEventSpec>forEach(_filter, _function_1);
+              _xblockexpression = (s);
+            }
+            return _xblockexpression;
+          }
+        };
+      IterableExtensions.<Transition, ArrayList<TimeEventSpec>>fold(_outgoingTransitions, tesList, _function);
+      EList<Reaction> _localReactions = state.getLocalReactions();
+      final Function2<ArrayList<TimeEventSpec>,Reaction,ArrayList<TimeEventSpec>> _function_2 = new Function2<ArrayList<TimeEventSpec>,Reaction,ArrayList<TimeEventSpec>>() {
+          public ArrayList<TimeEventSpec> apply(final ArrayList<TimeEventSpec> s_1 , final Reaction r_1) {
+            ArrayList<TimeEventSpec> _xblockexpression_1 = null;
+            {
+              List<EObject> _eAllContentsAsList_1 = EcoreUtil2.eAllContentsAsList(r_1);
+              Iterable<TimeEventSpec> _filter_1 = IterableExtensions.<TimeEventSpec>filter(_eAllContentsAsList_1, org.yakindu.sct.model.stext.stext.TimeEventSpec.class);
+              final Function1<TimeEventSpec,Boolean> _function_3 = new Function1<TimeEventSpec,Boolean>() {
+                  public Boolean apply(final TimeEventSpec tes_1) {
+                    boolean _add_1 = s_1.add(tes_1);
+                    return ((Boolean)_add_1);
+                  }
+                };
+              IterableExtensions.<TimeEventSpec>forEach(_filter_1, _function_3);
+              _xblockexpression_1 = (s_1);
+            }
+            return _xblockexpression_1;
+          }
+        };
+      IterableExtensions.<Reaction, ArrayList<TimeEventSpec>>fold(_localReactions, tesList, _function_2);
+      return tesList;
+    }
+  }
+  
+  protected ReactiveElement _reactiveElement(final Reaction r) {
+    Scope _scope = this.scope(r);
+    ReactiveElement _reactiveElement = this.reactiveElement(_scope);
+    return _reactiveElement;
+  }
+  
+  protected ReactiveElement _reactiveElement(final Transition tr) {
+    State _xifexpression = null;
+    Vertex _source = tr.getSource();
+    if ((_source instanceof org.yakindu.sct.model.sgraph.State)) {
+      _xifexpression = ((State) tr);
+    } else {
+      _xifexpression = null;
+    }
+    return _xifexpression;
+  }
+  
+  public Scope scope(final Reaction r) {
+    Scope _xifexpression = null;
+    EObject _eContainer = r.eContainer();
+    if ((_eContainer instanceof org.yakindu.sct.model.sgraph.Scope)) {
+      EObject _eContainer_1 = r.eContainer();
+      _xifexpression = ((Scope) _eContainer_1);
+    }
+    return _xifexpression;
+  }
+  
+  public ReactiveElement reactiveElement(final Scope s) {
+    ReactiveElement _xifexpression = null;
+    EObject _eContainer = s.eContainer();
+    if ((_eContainer instanceof org.yakindu.sct.model.sgraph.ReactiveElement)) {
+      EObject _eContainer_1 = s.eContainer();
+      _xifexpression = ((ReactiveElement) _eContainer_1);
+    }
+    return _xifexpression;
+  }
+  
+  public List<RegularState> allRegularStates(final Statechart sc) {
+    {
+      List<EObject> _eAllContentsAsList = EcoreUtil2.eAllContentsAsList(sc);
+      List<EObject> content = _eAllContentsAsList;
+      Iterable<RegularState> _filter = IterableExtensions.<RegularState>filter(content, org.yakindu.sct.model.sgraph.RegularState.class);
+      final Iterable<RegularState> allStates = _filter;
+      List<RegularState> _list = IterableExtensions.<RegularState>toList(allStates);
+      return _list;
+    }
+  }
+  
+  public List<Region> allRegions(final Statechart sc) {
+    {
+      List<EObject> _eAllContentsAsList = EcoreUtil2.eAllContentsAsList(sc);
+      List<EObject> content = _eAllContentsAsList;
+      Iterable<Region> _filter = IterableExtensions.<Region>filter(content, org.yakindu.sct.model.sgraph.Region.class);
+      final Iterable<Region> allRegions = _filter;
+      List<Region> _list = IterableExtensions.<Region>toList(allRegions);
+      return _list;
+    }
+  }
+  
+  public List<Choice> allChoices(final Statechart sc) {
+    {
+      List<EObject> _eAllContentsAsList = EcoreUtil2.eAllContentsAsList(sc);
+      List<EObject> content = _eAllContentsAsList;
+      Iterable<Choice> _filter = IterableExtensions.<Choice>filter(content, org.yakindu.sct.model.sgraph.Choice.class);
+      final Iterable<Choice> allChoices = _filter;
+      List<Choice> _list = IterableExtensions.<Choice>toList(allChoices);
+      return _list;
+    }
+  }
+  
+  public List<LocalReaction> entryReactions(final State state) {
+    EList<Reaction> _localReactions = state.getLocalReactions();
+    final Function1<Reaction,Boolean> _function = new Function1<Reaction,Boolean>() {
+        public Boolean apply(final Reaction r) {
+          Trigger _trigger = ((LocalReaction) r).getTrigger();
+          EList<EventSpec> _triggers = ((ReactionTrigger) _trigger).getTriggers();
+          final Function1<EventSpec,Boolean> _function_1 = new Function1<EventSpec,Boolean>() {
+              public Boolean apply(final EventSpec t) {
+                return (t instanceof org.yakindu.sct.model.stext.stext.EntryEvent);
+              }
+            };
+          boolean _exists = IterableExtensions.<EventSpec>exists(_triggers, _function_1);
+          return ((Boolean)_exists);
+        }
+      };
+    Iterable<Reaction> _filter = IterableExtensions.<Reaction>filter(_localReactions, _function);
+    final Function1<Reaction,LocalReaction> _function_2 = new Function1<Reaction,LocalReaction>() {
+        public LocalReaction apply(final Reaction lr) {
+          return ((LocalReaction) lr);
+        }
+      };
+    Iterable<LocalReaction> _map = IterableExtensions.<Reaction, LocalReaction>map(_filter, _function_2);
+    List<LocalReaction> _list = IterableExtensions.<LocalReaction>toList(_map);
+    return _list;
+  }
+  
+  public List<LocalReaction> exitReactions(final State state) {
+    EList<Reaction> _localReactions = state.getLocalReactions();
+    final Function1<Reaction,Boolean> _function = new Function1<Reaction,Boolean>() {
+        public Boolean apply(final Reaction r) {
+          Trigger _trigger = ((LocalReaction) r).getTrigger();
+          EList<EventSpec> _triggers = ((ReactionTrigger) _trigger).getTriggers();
+          final Function1<EventSpec,Boolean> _function_1 = new Function1<EventSpec,Boolean>() {
+              public Boolean apply(final EventSpec t) {
+                return (t instanceof org.yakindu.sct.model.stext.stext.ExitEvent);
+              }
+            };
+          boolean _exists = IterableExtensions.<EventSpec>exists(_triggers, _function_1);
+          return ((Boolean)_exists);
+        }
+      };
+    Iterable<Reaction> _filter = IterableExtensions.<Reaction>filter(_localReactions, _function);
+    final Function1<Reaction,LocalReaction> _function_2 = new Function1<Reaction,LocalReaction>() {
+        public LocalReaction apply(final Reaction lr) {
+          return ((LocalReaction) lr);
+        }
+      };
+    Iterable<LocalReaction> _map = IterableExtensions.<Reaction, LocalReaction>map(_filter, _function_2);
+    List<LocalReaction> _list = IterableExtensions.<LocalReaction>toList(_map);
+    return _list;
+  }
+  
+  protected String _id(final Object obj) {
+    return null;
+  }
+  
+  protected String _id(final Transition t) {
+    Comparable<? extends Object> _xifexpression = null;
+    Vertex _source = t.getSource();
+    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_source, null);
+    if (_operator_notEquals) {
+      Vertex _source_1 = t.getSource();
+      EList<Transition> _outgoingTransitions = _source_1.getOutgoingTransitions();
+      int _indexOf = _outgoingTransitions.indexOf(t);
+      _xifexpression = _indexOf;
+    } else {
+      _xifexpression = "";
+    }
+    String _operator_plus = StringExtensions.operator_plus("tr", _xifexpression);
+    return _operator_plus;
+  }
+  
+  protected String _id(final LocalReaction t) {
+    Comparable<? extends Object> _xifexpression = null;
+    ReactiveElement _reactiveElement = this.reactiveElement(t);
+    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_reactiveElement, null);
+    if (_operator_notEquals) {
+      ReactiveElement _reactiveElement_1 = this.reactiveElement(t);
+      EList<Reaction> _localReactions = _reactiveElement_1.getLocalReactions();
+      int _indexOf = _localReactions.indexOf(t);
+      _xifexpression = _indexOf;
+    } else {
+      _xifexpression = "";
+    }
+    String _operator_plus = StringExtensions.operator_plus("lr", _xifexpression);
+    return _operator_plus;
+  }
+  
+  public int maxOrthogonality(final Vertex s) {
+    if ((s instanceof State)) {
+      return _maxOrthogonality((State)s);
+    } else if ((s instanceof Vertex)) {
+      return _maxOrthogonality((Vertex)s);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        java.util.Arrays.<Object>asList(s).toString());
+    }
+  }
+  
+  public ReactiveElement reactiveElement(final Reaction tr) {
+    if ((tr instanceof Transition)) {
+      return _reactiveElement((Transition)tr);
+    } else if ((tr instanceof Reaction)) {
+      return _reactiveElement((Reaction)tr);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        java.util.Arrays.<Object>asList(tr).toString());
+    }
+  }
+  
+  public String id(final Object t) {
+    if ((t instanceof LocalReaction)) {
+      return _id((LocalReaction)t);
+    } else if ((t instanceof Transition)) {
+      return _id((Transition)t);
+    } else if ((t instanceof Object)) {
+      return _id((Object)t);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        java.util.Arrays.<Object>asList(t).toString());
+    }
+  }
+}