Posted by kohsuke
on September 19, 2006 at 2:33 PM PDT
My latest hobby project went online today. This project, named "sorcerer" generates HTML files from Java source code, and it does so in a way better than existing tools, thanks to the excellent javac tree API in JDK6.
My latest hobby project went online today. This project, named "sorcerer" generates HTML files from Java source code, and it does so in a way better than existing tools, thanks to the excellent javac tree API in JDK6. Just take a look at the sample report and see it for yourself.
There have been a few source code cross reference generators, like JXR in Maven and OpenGrok, but the problem I found with all of those tools is that they don't understand Java semantics. It can do lexical analysis, but none of them do the semantic analysis of the Java code. So the end result is that the generated HTML doesn't have much intelligence. The best it can do is to do syntax-coloring or do some keyword match (the tool basically just guess that this token MySAXParserFilterImpl probably means org/acme/MySAXParserFilterImpl.java.) I'm used to modern Java IDEs, so my expectation was higher.
This is where sorcerer does a better job. It actually builds the AST of Java source files, just like javac does (by using javac tree API .) So when it sees something like p.println(5) in your source file, it knows that "p" is a local variable defined in line 95 as PrintWriter, the println method invocation is PrintWriter.println(int), and so on.
Armed with this rich information, sorcerer can generate all kinds of useful navigation features that you often use with IDEs. In the version 0.1 I posted today, it does:
- jump to sub-classes, super-classes, etc.
- jump to methods that are overriding the current method
- jump to method overridden by the current method
- jump to definition of variables, methods, types, packages, etc.
I plan to add more navigations in the future — the top on the list is the "find usage" features. Another thing that I'd like to work on is to integrate source code from multiple projects into a single coherent view, so that you can navigate between projects seamlessly.
Meanwhile, the project should be already useful. It comes with CLI, ant task, and maven plugin. In particular, if you are using Maven2, it's dead-easy to set up. Read up the documentation on the website .