Chapter 4. Control Flow Graphs

JStyle can visually render the Control Flow Graph (CFG) of a Java method (not supported for native methods). Looking at the visual representation of a method’s control flow often helps in understanding the method’s logic. 

Comment generation must have been completed for the CFG to be displayed. There are two ways to bring up the graph of a method. One is to open a Java file in the editor window, position the cursor inside a method, and select Control Flow Graph from the context menu. The other is to highlight a method in the Class tab of the Project window, and select Control Flow Graph from the context menu. 

Consider the following class (the first column of each line shows the source line number). 

1 class CFGTest4 {
2      void test() throws E1 {
3            int i = 0;
4            if( i > 5 && i < 24 || i == -999)
5                  System.out.println("Condition is OK");
6            else
7                  throw new E1();
8      }
9 }

Its CFG appears like this:

Fig. 4.1

The above CFG representation is also made available to the scripting environment, so you can manipulate it programmatically if required.

Contents     Top    Previous   Next

Copyright © Man Machine Systems 1997-2003.
All Rights Reserved.
We acknowledge all trademarks.