In this last post I introduced you to some *very* basic understanding of how DGML works. Now I want to take that knowledge out for a test drive. :)
What I've decided to do is a couple of things. I've decided I'm going to show how to visualize Java code using Antlr and Visual Studio 2008 and output a DGML file that the VSTS 2010 Architecture product found in the latest CTP can render.
Why am I doing this? Because I think it will be an excellent example ( you'll be the judge of that ) of how easy it will be to visualize all kinds of data, not just .NET languages. Java code, Work Items, MSBuild dependencies, on and on. Literally, this list is potentially enormous, gated only by imagination and effort ( aren't all good things this way? ).
In some future posts, I'll show how you can continue to tweak the DGML to do some things that you can't do in the current CTP, but can with current bits ( such as node grouping, advanced selection, etc. ).
If you want to follow along on this little journey, you need to get the following things:
I'm going to be very descriptive of what I'm doing 'cause the complication is not going to be in the implementation, but more in the "configuration of the parts".
The executable created after building the solution is Java2DGML.exe. If you drop to the command line, CD into the debug directory where the exe is found, run the following command:
Java2DGML.exe /f %BOO%\antlr-3.1.1\src\org\antlr\Tool.java > Tool.dgml
then open Tool.dgml in the VSTS 2010 CTP, here's what you'll see:
Here's the XPS file of that image as well.
The exe is by no means a robust piece of software. It currently understands how to gather information for simple Java classes ( i.e., not templated ), fields, and methods. No interfaces, enums, etc., but after this post, you should have all the info you need to take this example a bit farther.
Now let me explain the source a little bit...
Here is a shot of the Solution Explorer with the Java2DGML solution loaded:
Java.Tokens, JavaLexer.cs, and JavaParser.cs are all generated files. You can regenerate those files by executing the following command in you command window where you executed BOO.bat, in the %BOO%\Java2DGML\Java2DGML directory:
java org.antlr.Tool Java.g
The Java.g file is where the grammar for parsing Java 1.5 is defined. This grammar file instructs the org.antlr.Tool object how to generate a parser in C# capable of parsing Java 1.5 code. More on this later.
A simple utility class used to gather information during the parse that is later used to generate the appropriate DGML. For every Java class, one DGMLContext object will be created to capture the relevant details.
Antlr has a great mechanism built in called the StringTemplate framework. Check out this link for more details. This file is an example of a StringTemplate for DGML files. More on this later.
Antlr allows the C# developer to tell Antlr to create a partial class for its parser implementation so that additional behavior can be added and used in the grammar file more easily. I've taken advantage of that in this file.
This is the main program, where all the pieces come together.
This post is really meant to whet your appetite on some of the possibilities coming in the 2010 version of the Architecture product around visualization. Admittedly, I'm clearly just scratching the surface of this particular example ( Java source visualization ), but that's ok. From time to time, I may come back to this example and flesh out a little more in order to exemplify some deeper features.
In the meantime, I think in my next post I'll start to show some more of the features inherent in DGML, beyond just the simple nodes and links I've shown to date.