问题
I need a tool to generate a control flow graph from java source code. Are there such tools available? Is there a possibility to also generate source code if I have a control flow graph?
回答1:
See my company's (Semantic Designs) Java Front End. It will compute control flow graphs for methods from source code.
The Java Front End is built on top of DMS Software Reengineering Toolkit, which provides generic machinery for manipulating (parsing, analyzing [e.g., extracting control flow graphs]), transformating, and generating) code.
If one has a particular control flow graph, DMS provides the machinery to enable you to build a graph walker, and from that you could reasonably build Java ASTs that can then be used to produce Java source code. Obviously your control flow graph would have to use vocabulary that translates into Java concepts easily (e.g., no Prolog "unify this" operators), or you will have much harder time generating corresponding Java code. If you generated the graph from Java code, this would clearly be the case.
回答2:
Sparx Systems' EA has a tool which hooks into a debugger and generates UML sequence diagrams:
From the Sparx marketing spiel:
The debuggers built into Enterprise Architect are specifically designed to enable a developer or tester to capture stack trace information as they ‘walk through’ the executing code, performing runtime inspection of suspended threads. They can then use the final stack trace history to generate Sequence diagrams within Enterprise Architect, converting the actual code execution and calls into visual diagrams.
I'm pretty sure that this is a one way transformation only - no round tripping.
来源:https://stackoverflow.com/questions/1542010/tools-for-generating-a-control-flow-graph-from-source-code