Permalink
Browse files

Merge pull request #1405 from umple/ISSUE_552

Fixes #552
  • Loading branch information...
TimLethbridge committed Nov 5, 2018
2 parents 4865a37 + def0514 commit 52e7e5307614eeedd8b0693ef250e9be20a51cea
@@ -2051,6 +2051,33 @@ the if(parent.getHasProxyPattern()) is neccessary to check if the parent's real
}
else if(!sm.getNestedStateMachines().isEmpty())
{
/**
fix for issue 552
**/
for (State s : sm.getStates())
{
for (Transition t : s.getTransitions())
{
Event e = t.getEvent();
if (!e.getIsTimer())
{
continue;
}
hasTimedEvents = true;
Action entryAction = new Action(StringFormatter.format("{0}();",translate("eventStartMethod",e)));
entryAction.setActionType("entry");
Action exitAction = new Action(StringFormatter.format("{0}();",translate("eventStopMethod",e)));
exitAction.setActionType("exit");
t.getFromState().addAction(entryAction);
t.getFromState().addAction(exitAction);
}
}
for (StateMachine nsm : sm.getNestedStateMachines())
{
for (State s : nsm.getStates())
@@ -461,6 +461,12 @@ public void pooledStateMachine_timedEvents()
assertUmpleTemplateFor("pooledStateMachine_timedEvents.ump",languagePath + "/pooledStateMachine_timedEvents."+ languagePath +".txt","Mentor");
}
@Test
public void nestedState_StateMachine_timedEvents()
{
assertUmpleTemplateFor("nestedStates_StateMachine_timedEvent.ump",languagePath + "/nestedStates_StateMachine_timedEvent."+ languagePath +".txt","Window");
}
@Test
public void pooledStateMachine()
{
@@ -0,0 +1,325 @@
/*PLEASE DO NOT EDIT THIS CODE*/
/*This code was generated using the UMPLE 1.29.1.4260.b21abf3a3 modeling language!*/
import java.util.*;
// line 1 "nestedStates_StateMachine_timedEvent.ump"
public class Window
{
//------------------------
// MEMBER VARIABLES
//------------------------
//Window State Machines
public enum WindowController { Stationary, SafetyMechanism }
public enum WindowControllerStationary { Null, NormalStationary }
private WindowController windowController;
private WindowControllerStationary windowControllerStationary;
//Helper Variables
private TimedEventHandler timeoutSafetyMechanismToStationaryHandler;
//------------------------
// CONSTRUCTOR
//------------------------
public Window()
{
setWindowControllerStationary(WindowControllerStationary.Null);
setWindowController(WindowController.Stationary);
}
//------------------------
// INTERFACE
//------------------------
public String getWindowControllerFullName()
{
String answer = windowController.toString();
if (windowControllerStationary != WindowControllerStationary.Null) { answer += "." + windowControllerStationary.toString(); }
return answer;
}
public WindowController getWindowController()
{
return windowController;
}
public WindowControllerStationary getWindowControllerStationary()
{
return windowControllerStationary;
}
public boolean timeoutSafetyMechanismToStationary()
{
boolean wasEventProcessed = false;
WindowController aWindowController = windowController;
switch (aWindowController)
{
case SafetyMechanism:
exitWindowController();
setWindowController(WindowController.Stationary);
wasEventProcessed = true;
break;
default:
// Other states do respond to this event
}
return wasEventProcessed;
}
public boolean down()
{
boolean wasEventProcessed = false;
WindowControllerStationary aWindowControllerStationary = windowControllerStationary;
switch (aWindowControllerStationary)
{
case NormalStationary:
exitWindowController();
setWindowController(WindowController.SafetyMechanism);
wasEventProcessed = true;
break;
default:
// Other states do respond to this event
}
return wasEventProcessed;
}
private void exitWindowController()
{
switch(windowController)
{
case Stationary:
exitWindowControllerStationary();
break;
case SafetyMechanism:
stopTimeoutSafetyMechanismToStationaryHandler();
break;
}
}
private void setWindowController(WindowController aWindowController)
{
windowController = aWindowController;
// entry actions and do activities
switch(windowController)
{
case Stationary:
// line 7 "nestedStates_StateMachine_timedEvent.ump"
if (windowControllerStationary == WindowControllerStationary.Null) { setWindowControllerStationary(WindowControllerStationary.NormalStationary); }
break;
case SafetyMechanism:
// line 18 "nestedStates_StateMachine_timedEvent.ump"
System.out.println("Safety mechanism");
startTimeoutSafetyMechanismToStationaryHandler();
break;
}
}
private void exitWindowControllerStationary()
{
switch(windowControllerStationary)
{
case NormalStationary:
setWindowControllerStationary(WindowControllerStationary.Null);
break;
}
}
private void setWindowControllerStationary(WindowControllerStationary aWindowControllerStationary)
{
windowControllerStationary = aWindowControllerStationary;
if (windowController != WindowController.Stationary && aWindowControllerStationary != WindowControllerStationary.Null) { setWindowController(WindowController.Stationary); }
// entry actions and do activities
switch(windowControllerStationary)
{
case NormalStationary:
// line 11 "nestedStates_StateMachine_timedEvent.ump"
System.out.println("Window is stopped");
break;
}
}
private void startTimeoutSafetyMechanismToStationaryHandler()
{
timeoutSafetyMechanismToStationaryHandler = new TimedEventHandler(this,"timeoutSafetyMechanismToStationary",100);
}
private void stopTimeoutSafetyMechanismToStationaryHandler()
{
timeoutSafetyMechanismToStationaryHandler.stop();
}
public static class TimedEventHandler extends TimerTask
{
private Window controller;
private String timeoutMethodName;
private double howLongInSeconds;
private Timer timer;
public TimedEventHandler(Window aController, String aTimeoutMethodName, double aHowLongInSeconds)
{
controller = aController;
timeoutMethodName = aTimeoutMethodName;
howLongInSeconds = aHowLongInSeconds;
timer = new Timer();
timer.schedule(this, (long)howLongInSeconds*1000);
}
public void stop()
{
timer.cancel();
}
public void run ()
{
if ("timeoutSafetyMechanismToStationary".equals(timeoutMethodName))
{
boolean shouldRestart = !controller.timeoutSafetyMechanismToStationary();
if (shouldRestart)
{
controller.startTimeoutSafetyMechanismToStationaryHandler();
}
return;
}
}
}
public void delete()
{}
// line 25 "nestedStates_StateMachine_timedEvent.ump"
public static void main(String [] argc){
Thread.currentThread().setUncaughtExceptionHandler(new UmpleExceptionHandler());
Thread.setDefaultUncaughtExceptionHandler(new UmpleExceptionHandler());
new Window1();
}
public static class UmpleExceptionHandler implements Thread.UncaughtExceptionHandler
{
public void uncaughtException(Thread t, Throwable e)
{
translate(e);
if(e.getCause()!=null)
{
translate(e.getCause());
}
e.printStackTrace();
}
public void translate(Throwable e)
{
java.util.List<StackTraceElement> result = new java.util.ArrayList<StackTraceElement>();
StackTraceElement[] elements = e.getStackTrace();
try
{
for(StackTraceElement element:elements)
{
String className = element.getClassName();
String methodName = element.getMethodName();
boolean methodFound = false;
int index = className.lastIndexOf('.')+1;
try {
java.lang.reflect.Method query = this.getClass().getMethod(className.substring(index)+"_"+methodName,new Class[]{});
UmpleSourceData sourceInformation = (UmpleSourceData)query.invoke(this,new Object[]{});
for(int i=0;i<sourceInformation.size();++i)
{
// To compensate for any offsets caused by injected code we need to loop through the other references to this function
// and adjust the start / length of the function.
int functionStart = sourceInformation.getJavaLine(i) + (("main".equals(methodName))?3:1);
int functionEnd = functionStart + sourceInformation.getLength(i);
int afterInjectionLines = 0;
// We can leverage the fact that all inject statements are added to the uncaught exception list
// before the functions that they are within
for (int j = 0; j < i; j++) {
if (sourceInformation.getJavaLine(j) - 1 >= functionStart &&
sourceInformation.getJavaLine(j) - 1 <= functionEnd &&
sourceInformation.getJavaLine(j) - 1 <= element.getLineNumber()) {
// A before injection, +2 for the comments surrounding the injected code
if (sourceInformation.getJavaLine(j) - 1 == functionStart) {
functionStart += sourceInformation.getLength(j) + 2;
functionEnd += sourceInformation.getLength(j) + 2;
} else {
// An after injection
afterInjectionLines += sourceInformation.getLength(j) + 2;
functionEnd += sourceInformation.getLength(j) + 2;
}
}
}
int distanceFromStart = element.getLineNumber() - functionStart - afterInjectionLines;
if(distanceFromStart>=0&&distanceFromStart<=sourceInformation.getLength(i))
{
result.add(new StackTraceElement(element.getClassName(),element.getMethodName(),sourceInformation.getFileName(i),sourceInformation.getUmpleLine(i)+distanceFromStart));
methodFound = true;
break;
}
}
}
catch (Exception e2){}
if(!methodFound)
{
result.add(element);
}
}
}
catch (Exception e1)
{
e1.printStackTrace();
}
e.setStackTrace(result.toArray(new StackTraceElement[0]));
}
//The following methods Map Java lines back to their original Umple file / line
public UmpleSourceData Window_setWindowControllerStationary(){ return new UmpleSourceData().setFileNames("nestedStates_StateMachine_timedEvent.ump").setUmpleLines(10).setJavaLines(147).setLengths(1);}
public UmpleSourceData Window_main(){ return new UmpleSourceData().setFileNames("nestedStates_StateMachine_timedEvent.ump").setUmpleLines(24).setJavaLines(199).setLengths(1);}
public UmpleSourceData Window_setWindowController(){ return new UmpleSourceData().setFileNames("nestedStates_StateMachine_timedEvent.ump","nestedStates_StateMachine_timedEvent.ump").setUmpleLines(6, 17).setJavaLines(115, 120).setLengths(1, 1);}
}
public static class UmpleSourceData
{
String[] umpleFileNames;
Integer[] umpleLines;
Integer[] umpleJavaLines;
Integer[] umpleLengths;
public UmpleSourceData(){
}
public String getFileName(int i){
return umpleFileNames[i];
}
public Integer getUmpleLine(int i){
return umpleLines[i];
}
public Integer getJavaLine(int i){
return umpleJavaLines[i];
}
public Integer getLength(int i){
return umpleLengths[i];
}
public UmpleSourceData setFileNames(String... filenames){
umpleFileNames = filenames;
return this;
}
public UmpleSourceData setUmpleLines(Integer... umplelines){
umpleLines = umplelines;
return this;
}
public UmpleSourceData setJavaLines(Integer... javalines){
umpleJavaLines = javalines;
return this;
}
public UmpleSourceData setLengths(Integer... lengths){
umpleLengths = lengths;
return this;
}
public int size(){
return umpleFileNames.length;
}
}
}
Oops, something went wrong.

0 comments on commit 52e7e53

Please sign in to comment.