Skip to content

Instantly share code, notes, and snippets.

@jblang94
Created February 28, 2017 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jblang94/f96cd9eb8ba0a5323328f6adfeb429ca to your computer and use it in GitHub Desktop.
Save jblang94/f96cd9eb8ba0a5323328f6adfeb429ca to your computer and use it in GitHub Desktop.
Issue 935 - Solution Approach 1
/*
The current code includes the methods "exitSmOn" and "exitSmOnS1".
Within these methods, the exit actions exit_s1_execute() and exit_m1_execute() are called respectively.
In this version of the solution, the methods "exitSmOn" and "exitSmOnS1" would not be generated,
exit_s1_execute() and exit_m1_execute() are moved to exitOn().
*/
public boolean e12()
{
boolean wasEventProcessed = false;
SmOnS1 aSmOnS1 = smOnS1;
switch (aSmOnS1)
{
case m1:
// exitSmOnS1(); this is the current call in the generated code
// Instead, call exitSm() since all transitions in Umple are considered as external transitions
// While my example pertains to "e12", my idea is for all event methods
// (e1 -> e12) to use exitSm();
exitSm();
setSm(Sm.off);
wasEventProcessed = true;
break;
default:
// Other states do respond to this event
}
return wasEventProcessed;
}
// No changes for exitSm()
private void exitSm()
{
switch(sm)
{
case on:
exitOn();
// line 4 "checkExternalTransitions_withExitActions_1.ump"
exit_on_execute();
break;
}
}
private boolean exitOn()
{
boolean wasEventProcessed = false;
SmOn aSmOn = smOn;
SmOnS1 aSmOnS1 = smOnS1;
// First check if we are in state "m1",
// Currently the generated code checks if we are in "s1" first
switch (aSmOnS1)
{
case m1:
exit_m1_execute(); // Add m1 exit action
setSmOnS1(SmOnS1.Null);
wasEventProcessed = true;
break;
case m2:
setSmOnS1(SmOnS1.Null);
wasEventProcessed = true;
break;
default:
// Other states do respond to this event
}
// Now check if we are in state "s1"
switch (aSmOn)
{
case s1:
exit_s1_execute(); // Add s1 exit action
setSmOn(SmOn.Null);
wasEventProcessed = true;
break;
case s2:
setSmOn(SmOn.Null);
wasEventProcessed = true;
break;
default:
// Other states do respond to this event
}
return wasEventProcessed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment