Skip to content

Commit

Permalink
Update handling of regional final states
Browse files Browse the repository at this point in the history
* Fix exit action calls for concurrent state machines
* Update existing getFinalStates function
* Update getConcurrentRegion
* Update existing tests
  • Loading branch information
jblang94 committed Apr 3, 2017
1 parent 8cdb0fb commit f60a2d2
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 29 deletions.
38 changes: 19 additions & 19 deletions UmpleToJava/UmpleTLTemplates/state_machine_Event.ump
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,21 @@ class UmpleToJava {
State fromConcurrentParentState = state.getConcurrentParentState();
if (fromConcurrentParentState != null) {
StateMachine concurrentSmToExit = null;

if (nextState.getStateMachine().equals(superStateMachine)) {
concurrentSmToExit = superStateMachine;
} else if (state.getStateMachine().equals(nextState.getStateMachine())) {
concurrentSmToExit = state.getStateMachine();
} else {
State nextConcurrentParentState = nextState.getConcurrentParentState();
concurrentSmToExit = t.getSmToExit(superStateMachine);
if (nextConcurrentParentState != null) {
if (fromConcurrentParentState.equals(nextConcurrentParentState)) {
transitionIsAndCross = true;
concurrentParent = fromConcurrentParentState;
concurrentSmToExit = fromConcurrentParentState.getStateMachine();
} else {
concurrentSmToExit = superStateMachine;
if (t.isTransitionAndCross(fromConcurrentParentState)) {
concurrentParent = fromConcurrentParentState;
transitionIsAndCross = true;
}
}
} else {
concurrentSmToExit = superStateMachine;
}
}

Expand Down Expand Up @@ -205,22 +203,24 @@ class UmpleToJava {

// Issue 935 - Additional processing for concurrent state machines
if (transitionIsAndCross) {
for (StateMachine smToReset : concurrentParent.getNestedStateMachines()) {
boolean reset = true;
if(smToReset.indexOfState(nextState) != -1) {
reset = false;
} else {
for(StateMachine nestedStateMachine : smToReset.getNestedStateMachines()) {
if (nestedStateMachine.indexOfState(nextState) != -1) {
reset = false;
break;
}
for (StateMachine smToReset : concurrentParent.getNestedStateMachines()) {
if (smToReset.indexOfState(state) != -1) {
allCases.append(StringFormatter.format("{0}{1}({2}.{3});\n",tabSpace,gen.translate("setMethod", smToReset),gen.translate("type", smToReset),gen.translate("stateOne", smToReset.getStartState())));
break;
} else {
boolean reset = false;
for(StateMachine nestedStateMachine : smToReset.getNestedStateMachines()) {
if (nestedStateMachine.indexOfState(state) != -1) {
reset = true;
break;
}
}
if (reset) {
allCases.append(StringFormatter.format("{0}{1}({2}.{3});\n",tabSpace,gen.translate("setMethod", smToReset),gen.translate("type", smToReset),gen.translate("stateOne", smToReset.getStartState())));
allCases.append(StringFormatter.format("{0}{1}({2}.{3});\n",tabSpace,gen.translate("setMethod", smToReset),gen.translate("type", smToReset),gen.translate("stateOne", smToReset.getStartState())));
break;
}
}
}
}
// allCases.append(traceItem!=null&&traceItem.getIsPost()?traceItem.trace(gen, t,"sm_t", uClass)+"\n":"");

Expand Down
24 changes: 24 additions & 0 deletions cruise.umple/src/StateMachine_Code.ump
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class StateMachine
public List<State> getFinalStates()
{
List<StateMachine> all = new ArrayList<StateMachine>();
all.add(this);
all.addAll(getNestedStateMachines());
return getFinalStatesIn(all);
}
Expand Down Expand Up @@ -703,6 +704,8 @@ class State
}
traverser = traverser.getStateMachine().getParentState();
}
} else if (this.getIsConcurrent()) {
concurrentRegion = this;
}
return concurrentRegion;
}
Expand Down Expand Up @@ -785,6 +788,27 @@ class Transition

return smToExit;
}

/*
Issue 140/935 - A helper function to determine if a transition is an and-cross transition
*/
public boolean isTransitionAndCross(State commonConcurrentParent)
{
// We've already determined that fromState and nextState are in the same concurrent parent state
// However, we need to check if fromState and nextState belong to different state machines
// within the concurrent parent state
StateMachine fromStateSm = fromState.getStateMachine();
StateMachine nextStateSm = nextState.getStateMachine();

while (!fromStateSm.getParentState().equals(commonConcurrentParent)) {
fromStateSm = fromStateSm.getParentState().getStateMachine();
}

while (!nextStateSm.getParentState().equals(commonConcurrentParent)) {
nextStateSm = nextStateSm.getParentState().getStateMachine();
}
return !fromStateSm.equals(nextStateSm);
}
}

class Event
Expand Down
4 changes: 2 additions & 2 deletions cruise.umple/test/cruise/umple/compiler/StateMachineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public void hasFinalStates_NotConcurrent()
new State("s1",sm);
Assert.assertEquals(false,sm.hasFinalStates());
new State("Final",sm);
Assert.assertEquals(false,sm.hasFinalStates());
Assert.assertEquals(true,sm.hasFinalStates());
}

@Test
Expand Down Expand Up @@ -551,7 +551,7 @@ public void getFinalStates_NotConcurrent()
new State("s1",sm);
Assert.assertEquals(0,sm.getFinalStates().size());
new State("Final",sm);
Assert.assertEquals(0,sm.getFinalStates().size());
Assert.assertEquals(1,sm.getFinalStates().size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,4 +871,10 @@ public void testRegionFinalStates_5()
assertUmpleTemplateFor("testRegionFinalStates_5.ump",languagePath + "/testRegionFinalStates_5."+ languagePath +".txt","X");
}

@Test
public void testRegionFinalStates_6()
{
assertUmpleTemplateFor("testRegionFinalStates_6.ump",languagePath + "/testRegionFinalStates_6."+ languagePath +".txt","X");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class X
switch (aSmS1AA)
{
case t2:
exitSm();
exitSmS1A();
setSmS1BB(SmS1BB.t4);
setSmS1A(SmS1A.a);
wasEventProcessed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public class X
switch (aSmS1S2BB)
{
case t3:
exitSm();
exitSmS1S2();
setSmS1S3S3(SmS1S3S3.t5);
wasEventProcessed = true;
break;
Expand Down Expand Up @@ -207,7 +207,7 @@ public class X
switch (aSmS1S3S3)
{
case t6:
exitSm();
exitSmS1S2();
setSmS1S2AA(SmS1S2AA.t2);
wasEventProcessed = true;
break;
Expand Down Expand Up @@ -407,4 +407,4 @@ public class X
public void delete()
{}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ public class X
switch (aSmS1S2T6)
{
case t6:
exitSmS1();
exitSmS1S2T6();
setSmS1S2T2(SmS1S2T2.t5);
setSmS1S2T1(SmS1S2T1.t1);
setSmS1S2T6(SmS1S2T6.t6);
wasEventProcessed = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class QueuedWithConcurrentStateMachines implements Runnable
switch (aSmS2S2a)
{
case s2a:
exitSm();
exitSmS2S2a();
setSmS2S2b(SmS2S2b.s2b);
setSmS2S2a(SmS2S2a.s2a);
wasEventProcessed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class X
switch (aSmS1S2)
{
case s2:
exitSm();
exitSmS1S2();
setSmS1S3(SmS1S3.s3);
setSmS1S2(SmS1S2.s2);
wasEventProcessed = true;
Expand Down
Loading

0 comments on commit f60a2d2

Please sign in to comment.