Friday, March 27, 2009

GUI tool for discovering class relationships idea

I work a lot with libraries of code which I did not write myself.
I also have this problem with my own code but more often with sets of "foreign" code.
The problem is that I can end up with an 'impedance mismatch' between types and need to figure out how to match them up. Say I end up with class A but need a class B.
I'm hoping there is some way to convert A to B. A real example recently I had a XdmNode and wanted an XMLStreamReader. In a simple case I would look in A and see if there is a method that returns B, or look in B and see if there is a constructor that takes A. But in the real world its rarely that simple, there are frequently dependency issues and also chains of transformations. Eg. to convert A to B might require a C, or might require going through an intermediary path like A->D->B.
In the above real example, the path ended up being

XdmValue -> ValueRepresentation -> { Value | NodeInfo } -> SequenceIterator -> PullFromIterator -> PullToStax -> XMLStreamReader

Thats 6 levels of transformations ! I have been working in that codebase for several years and still it took some hints from the author to figure it out, and then lots of luck.

This got me thinking ... Wouldn't it be nice if there was a tool for this task ?
There are lots of java class browsers (I use the Package explorer in Eclipse),
but none that I know of that do this job. Given 2 classes, show all the paths between the classes as well as all the dependencies along the paths.

Now to be really useful, the routes need to be appropriate, as well as existent.
For example, in the above example, I first found, and used, a different path from XdmValue to XMLStreamReader that turned out used a class which was not entirely functional (It lost Location information). There's no way I can imagine a tool knowing this short of AI. Which leads to a whole different set of ideas, an AI that can understand software. Something you could ask "Whats the best way to create an XMLStream from an XdmNode in this context". Or maybe "will this code actually work right ?", "Please generate unit tests for this set of code and run them and show me what broke and why".

This seems an awful lot like "Theorm Prover" software that in the 70's and 80's was being worked on agressively, but I havent heard much of since.

No comments:

Post a Comment

Due to comment spam, moderation is turned on. I will approve all non-spam comments.