A blog about software development and other software related matters

Blog Archive

Thursday, August 21, 2008

Code is data or so they say..

Iv been writing some custom checkstyle checks, the process of doing so is laborious and annoying, checkstyle uses an ANTLR visitor to allow the programmer to validate the tokens he wishes, this approach doesn't scale too well since it makes the programmer think of the "how" and not on "what", by that i mean that instead of being declarative its imperative.
After writing a couple of those it made me realize that there must be a better tool in which i could query the code instead of running along side the it, as a matter of a fact we are using such a tool every day, the IDE.
In the IDE we search for types, usages and other rather limited queries, we overcome these limitations by traversing the code wisely however there are still much more left be desired, for example the following query:

select field from classes where class.package=com.jdftm.* and field.visibilty=protected

which finds all the protected fields within the com.jdftm package, this kind of queries can be usefully not only on build time but also on development and runtime!

The runtime usage might sound a bit awkward but it might prove to be very powerful, imagine that we wish to write a test which validates that all the classes in com.jdftm package will not accept null parameters in any of their public methods, its possible to do so with some laborious reflection code but doing with a query tool would be much cleaner and easier to follow.

It seems that im not the first one to think in this direction still i would like to find some library that can run in pure Java code (no IDE dependency).

After yet some more googeling iv found yet two more interesting tools javaML and bbq

No comments: