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?
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.