This post presents a new Reflector Addin that creates and diplays the graph of statement inside methods: the StatementGraph. This addin is an evolution of the IL graph. (this addin is not yet available for download).
The statement graph is built from the Reflector CodeModel where each IStatement instance is a vertex and edges are added accordingly to the code "flow" (creating the edges is the most involved task). The rest of the job is handled by the QuickGraph library. When it makes sense, the vertices are clickable and you can jump to the invoked method, etc... The next step will be to update the Automatic Unit Test generator with the StatementGraph...
Let's see some simple methods and their corresponding graphs:
Simple
public void Simple() { Console.WriteLine("hello"); }
Two statements in sequence
public void Body() { Console.WriteLine("hello"); Console.WriteLine("world"); }
If - Then - Else
public void If(int value) { if (value<0) Console.WriteLine("true"); else Console.WriteLine("false"); }
public void If(int value) { if (value < 0) { Console.WriteLine("true"); return; } Console.WriteLine("false"); }
While
public void While() { int i = 0; while(i<10) { Console.Write(i++); } }
public void While() { int num1 = 0; while ((num1 < 10)) { Console.Write(num1++); } }
While with break and continue
public void WhileBreakContinue() { int i = 0; while (i < 10) { if (i == 5) continue; if (i == 7) break; Console.Write(i++); } Console.WriteLine("Finished"); }
public void WhileBreakContinue() { int num1 = 0; while ((num1 < 10)) { if (num1 == 5) { continue; } if (num1 == 7) { break; } Console.Write(num1++); } Console.WriteLine("Finished"); }
Try - Catch
public void TryCatch() { try { Console.WriteLine("hello"); } catch (Exception ex) { Console.WriteLine("Boom: {0}",ex); } }
public void TryCatch() { try { Console.WriteLine("hello"); } catch (Exception exception1) { Console.WriteLine("Boom: {0}", exception1); } }
Page rendered at Monday, October 13, 2008 12:06:15 PM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.