📄 smcjavagenerator.java
字号:
_source.print(fqEndStateName); _source.println(" = context.getState();"); } else { fqEndStateName = endStateName; } // Decide if runtime loopback checking must be done. if (defaultFlag == true && transType != Smc.TRANS_POP && loopbackFlag == false) { _source.print(indent2); _source.println("boolean loopbackFlag ="); _source.print(indent2); _source.println( " context.getState().getName().equals("); _source.print(indent2); _source.print(" "); _source.print(fqEndStateName); _source.println(".getName());"); } _source.println(); // Dump out the exit actions - but only for the first // guard. // v. 1.0, beta 3: Not any more. The exit actions are // executed only if 1) this is a standard, non-loopback // transition or a pop transition. if (transType == Smc.TRANS_POP || loopbackFlag == false) { indent4 = indent2; // If this is a non-loopback, generic transition, // do runtime loopback checking. if (transType == Smc.TRANS_SET && defaultFlag == true) { indent4 = indent2 + " "; _source.print(indent2); _source.println("if (loopbackFlag == false)"); _source.print(indent2); _source.println('{'); } _source.print(indent4); _source.println( "(context.getState()).Exit(context);"); if (transType == Smc.TRANS_SET && defaultFlag == true) { _source.print(indent2); _source.println('}'); _source.println(); } } // Dump out this transition's actions. if (hasActions == false) { if (condition.length() > 0) { _source.print(indent2); _source.println("// No actions."); } indent3 = indent2; } else { // Now that we are in the transition, clear the // current state. _source.print(indent2); _source.println("context.clearState();"); // v. 2.0.0: Place the actions inside a try/finally // block. This way the state will be set before an // exception leaves the transition method. // v. 2.2.0: Check if the user has turned off this // feature first. if (Smc.isNoCatch() == false) { _source.print(indent2); _source.println("try"); _source.print(indent2); _source.println('{'); indent3 = indent2 + " "; } else { indent3 = indent2; } indent4 = _indent; _indent = indent3; for (SmcAction action: actions) { action.accept(this); } _indent = indent4; // v. 2.2.0: Check if the user has turned off this // feature first. if (Smc.isNoCatch() == false) { _source.print(indent2); _source.println('}'); _source.print(indent2); _source.println("finally"); _source.print(indent2); _source.println('{'); } } // Print the setState() call, if necessary. Do NOT // generate the set state it: // 1. The transition has no actions AND is a loopback OR // 2. This is a push or pop transition. if (transType == Smc.TRANS_SET && (hasActions == true || loopbackFlag == false)) { _source.print(indent3); _source.print("context.setState("); _source.print(fqEndStateName); _source.println(");"); } else if (transType == Smc.TRANS_PUSH) { // Set the next state so this it can be pushed // onto the state stack. But only do so if a clear // state was done. if (loopbackFlag == false || hasActions == true) { _source.print(indent3); _source.print("context.setState("); _source.print(fqEndStateName); _source.println(");"); } // Before doing the push, execute the end state's // entry actions (if any) if this is not a loopback. if (loopbackFlag == false) { if (defaultFlag == true) { indent4 = indent3 + " "; _source.println(); _source.print(indent3); _source.println( "if (loopbackFlag == false)"); _source.print(indent3); _source.println('{'); } else { indent4 = indent3; } _source.print(indent4); _source.println( "(context.getState()).Entry(context);"); if (defaultFlag == true) { _source.print(indent3); _source.println('}'); } } _source.print(indent3); _source.print("context.pushState("); _source.print(pushStateName); _source.println(");"); } else if (transType == Smc.TRANS_POP) { _source.print(indent3); _source.println("context.popState();"); } // Perform the new state's enty actions. // v. 1.0, beta 3: Not any more. The entry actions are // executed only if 1) this is a standard, non-loopback // transition or a push transition. if ((transType == Smc.TRANS_SET && loopbackFlag == false) || transType == Smc.TRANS_PUSH) { indent4 = indent3; // If this is a non-loopback, generic transition, // do runtime loopback checking. if (transType == Smc.TRANS_SET && defaultFlag == true) { indent4 = indent3 + " "; _source.println(); _source.print(indent3); _source.println("if (loopbackFlag == false)"); _source.print(indent3); _source.println('{'); } _source.print(indent4); _source.println( "(context.getState()).Entry(context);"); if (transType == Smc.TRANS_SET && defaultFlag == true) { _source.print(indent3); _source.println('}'); _source.println(); } } // If there was a try/finally, then put the closing // brace on the finally block. // v. 2.2.0: Check if the user has turned off this // feature first. if (hasActions == true && Smc.isNoCatch() == false) { _source.print(indent2); _source.println('}'); } // If there is a transition associated with the pop, then // issue that transition here. if (transType == Smc.TRANS_POP && endStateName.equals(NIL_STATE) == false && endStateName.length() > 0) { String popArgs = guard.getPopArgs(); _source.println(); _source.print(indent2); _source.print("context."); _source.print(endStateName); _source.print("("); // Output any and all pop arguments. if (popArgs.length() > 0) { _source.print(popArgs); } _source.println(");"); } // If this is a guarded transition, it will be necessary // to close off the "if" body. DON'T PRINT A NEW LINE! // Why? Because an "else" or "else if" may follow and we // won't know until we go back to the transition source // generator whether all clauses have been done. if (_guardCount > 1) { _source.print(_indent); _source.print(" }"); } return; } // end of visit(SmcGuard) public void visit(SmcAction action) { String name = action.getName(); Iterator<String> it; String sep; // Need to distinguish between FSMContext actions and // application class actions. If the action is // "emptyStateStack", then pass it to the context. // Otherwise, let the application class handle it. _source.print(_indent); if (name.equals("emptyStateStack") == true) { _source.print("context."); } else { _source.print("ctxt."); } _source.print(name); _source.print("("); for (it = action.getArguments().iterator(), sep = ""; it.hasNext() == true; sep = ", ") { _source.print(sep); _source.print(it.next()); } _source.println(");"); return; } // end of visit(SmcAction) public void visit(SmcParameter parameter) { _source.print(parameter.getType()); _source.print(' '); _source.print(parameter.getName()); return; } // end of visit(SmcParameter)//---------------------------------------------------------------// Member data//} // end of class SmcJavaGenerator//// CHANGE LOG// $Log: SmcJavaGenerator.java,v $// Revision 1.11 2008/03/21 14:03:16 fperrad// refactor : move from the main file Smc.java to each language generator the following data :// - the default file name suffix,// - the file name format for the generated SMC files//// Revision 1.10 2007/02/21 13:55:32 cwrapp// Moved Java code to release 1.5.0//// Revision 1.9 2007/01/15 00:23:51 cwrapp// Release 4.4.0 initial commit.//// Revision 1.8 2006/09/16 15:04:29 cwrapp// Initial v. 4.3.3 check-in.//// Revision 1.7 2006/06/03 19:39:25 cwrapp// Final v. 4.3.1 check in.//// Revision 1.6 2005/11/07 19:34:54 cwrapp// Changes in release 4.3.0:// New features://// + Added -reflect option for Java, C#, VB.Net and Tcl code// generation. When used, allows applications to query a state// about its supported transitions. Returns a list of transition// names. This feature is useful to GUI developers who want to// enable/disable features based on the current state. See// Programmer's Manual section 11: On Reflection for more// information.//// + Updated LICENSE.txt with a missing final paragraph which allows// MPL 1.1 covered code to work with the GNU GPL.//// + Added a Maven plug-in and an ant task to a new tools directory.// Added Eiten Suez's SMC tutorial (in PDF) to a new docs// directory.//// Fixed the following bugs://// + (GraphViz) DOT file generation did not properly escape// double quotes appearing in transition guards. This has been// corrected.//// + A note: the SMC FAQ incorrectly stated that C/C++ generated// code is thread safe. This is wrong. C/C++ generated is// certainly *not* thread safe. Multi-threaded C/C++ applications// are required to synchronize access to the FSM to allow for// correct performance.//// + (Java) The generated getState() method is now public.//// Revision 1.5 2005/09/14 01:51:33 cwrapp// Changes in release 4.2.0:// New features://// None.//// Fixed the following bugs://// + (Java) -java broken due to an untested minor change.//// Revision 1.4 2005/08/26 15:21:34 cwrapp// Final commit for release 4.2.0. See README.txt for more information.//// Revision 1.3 2005/06/30 10:44:23 cwrapp// Added %access keyword which allows developers to set the generate Context// class' accessibility level in Java and C#.//// Revision 1.2 2005/06/18 18:28:42 cwrapp// SMC v. 4.0.1//// New Features://// (No new features.)//// Bug Fixes://// + (C++) When the .sm is in a subdirectory the forward- or// backslashes in the file name are kept in the "#ifndef" in the// generated header file. This is syntactically wrong. SMC now// replaces the slashes with underscores.//// + (Java) If %package is specified in the .sm file, then the// generated *Context.java class will have package-level access.//// + The Programmer's Manual had incorrect HTML which prevented the// pages from rendering correctly on Internet Explorer.//// + Rewrote the Programmer's Manual section 1 to make it more// useful.//// Revision 1.1 2005/05/28 19:28:42 cwrapp// Moved to visitor pattern.//// Revision 1.2 2005/02/21 15:35:45 charlesr// Added Francois Perrad to Contributors section for Python work.//// Revision 1.1 2005/02/21 15:18:32 charlesr// Modified isLoopback() to new signature due to moving method from// SmcGuard to SmcCodeGenerator.// Corrected indentation for "loopbackFlag =" statement.// Declaring "boolean loopbackFlag" only if and where it is needed.//// Revision 1.0 2005/02/03 17:11:27 charlesr// Initial revision//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -