📄 smcgraphgenerator.java
字号:
else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream pstream = _source; String sep; _source = new PrintStream(baos); for (pit = parameters.iterator(), sep = ""; pit.hasNext() == true; sep = ", ") { (pit.next()).accept(this); } _parameters = baos.toString(); _source = pstream; } } for (SmcGuard guard: transition.getGuards()) { _source.println(); guard.accept(this); } return; } // end of visit(SmcTransition) public void visit(SmcGuard guard) { SmcTransition transition = guard.getTransition(); SmcState state = transition.getState(); SmcMap map = state.getMap(); String mapName = map.getName(); String stateName = state.getInstanceName(); String transName = transition.getName(); int transType = guard.getTransType(); String endStateName = guard.getEndState(); String pushStateName = guard.getPushState(); String condition = guard.getCondition(); int graphLevel = Smc.graphLevel(); List<SmcAction> actions = guard.getActions(); _source.print(" \""); _source.print(mapName); _source.print("::"); _source.print(stateName); _source.print("\" -> "); if (transType != Smc.TRANS_POP) { if (endStateName.equals(NIL_STATE) == true) { endStateName = mapName + "::" + stateName; } else if (endStateName.indexOf("::") < 0) { endStateName = mapName + "::" + endStateName; } _source.print("\""); _source.print(endStateName); _source.println("\""); } else { String popArgs = guard.getPopArgs(); _source.print("\""); _source.print(mapName); _source.print("::pop("); _source.print(endStateName); if (graphLevel == Smc.GRAPH_LEVEL_2 && popArgs != null && popArgs.length() > 0) { _source.print(", "); _source.print(Smc.escape(popArgs)); } _source.println(")\""); } _source.print(" [label=\""); _source.print(transName); // Graph Level 2: Output the transition parameters. if (graphLevel == Smc.GRAPH_LEVEL_2 && _parameters != null && _parameters.length() > 0) { _source.print("("); _source.print(_parameters); _source.print(")"); } // Graph Level 1, 2: Output the guard. if (graphLevel > Smc.GRAPH_LEVEL_0 && condition != null && condition.length() > 0) { String continueLine = "\\\\"; _source.print("\\l\\["); // If the condition contains line separators, // then replace them with a "\n" so Graphviz knows // about the line separation. // 4.3.0: First escape the condition then replace the // line separators. _source.print( Smc.escape(condition).replaceAll( "\\n", "\\\\\\n")); _source.print("\\]"); } if (transType == Smc.TRANS_PUSH) { _source.print("/\\lpush("); _source.print(pushStateName); _source.print(")"); } // Graph Level 1, 2: output actions. if (graphLevel > Smc.GRAPH_LEVEL_0 && actions != null && actions.isEmpty() == false) { _source.print("/\\l"); for (SmcAction action: actions) { action.accept(this); _source.print("\\l"); } } _source.print("\"];"); return; } // end of visit(SmcGuard) public void visit(SmcAction action) { int graphLevel = Smc.graphLevel(); // Actions are only reported for graph levels 1 and 2. // Graph level 1: only the action name, no arguments. // Graph level 2: action name and arguments. // // Note: do not output an end-of-line. if (graphLevel >= Smc.GRAPH_LEVEL_1) { _source.print(action.getName()); if (graphLevel == Smc.GRAPH_LEVEL_2) { Iterator<String> it; String arg; String sep; _source.print("("); // Now output the arguments. for (it = action.getArguments().iterator(), sep = ""; it.hasNext() == true; sep = ", ") { arg = (it.next()).trim(); _source.print(sep); // If the argument is a quoted string, then // the quotes must be escaped. // First, replace all backslashes with two // backslashes. arg = arg.replaceAll("\\\\", "\\\\\\\\"); // Then replace all double quotes with // a backslash double qoute. _source.print( arg.replaceAll("\"", "\\\\\"")); } _source.print(")"); } _source.print(';'); } return; } // end of visit(SmcAction) public void visit(SmcParameter parameter) { _source.print(parameter.getName()); _source.print(": "); _source.print(parameter.getType()); return; } // end of visit(SmcParameter)//---------------------------------------------------------------// Member data// // Store the serialized parameters here. private String _parameters;} // end of class SmcGraphGenerator//// CHANGE LOG// $Log: SmcGraphGenerator.java,v $// Revision 1.8 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.7 2007/12/28 12:34:41 cwrapp// Version 5.0.1 check-in.//// Revision 1.6 2007/02/21 13:54:51 cwrapp// Moved Java code to release 1.5.0//// Revision 1.5 2007/01/15 00:23:51 cwrapp// Release 4.4.0 initial commit.//// Revision 1.4 2006/09/16 15:04:29 cwrapp// Initial v. 4.3.3 check-in.//// Revision 1.3 2006/07/11 18:13:33 cwrapp// Changed method getGraphLevel() to graphLevel().//// Revision 1.2 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.1 2005/05/28 19:28:42 cwrapp// Moved to visitor pattern.//// Revision 1.1 2005/02/21 15:35:19 charlesr// Added Francois Perrad to Contributors section for Python work.//// Revision 1.0 2005/02/03 17:10:52 charlesr// Initial revision//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -