I'm writing a tool in Java that will generate API documentation similar to Javadoc, but without the requirement for special tags or comments in the source code file. The result will be professional looking API documentation without cluttered source code.
I would like to build my tool with some existing code that parses a java source code file and provides methods that will allow me to access the different parts of the source code file. In particular, I need to be able to pull out method declarations and variable declarations.
I know that this type of java source code parser must exist as part of an existing IDE like Eclipse or JEdit. Does anyone know of a tool or group of classes that will help me parse a Java source code file and access its elements?
Thanks for any information.
posted 14 years ago
I was able to answer my own question, after digging around the Javadoc for Eclipse. I wanted to post my answer here, in case someone else was interested.
The package in Eclipse that contains the classes I need to use is:
In particular, I think I will be using the subclasses of the AST class and also the ASTParser class.
Parsing source code is very tough because language syntax is so complex. For your task, you might look into the doclet APIs. The JavaDoc tool does the heavy lifting (and parsing) and hands all the parsed information to the doclet to write whatever it wants. The standard doclet writes JavaDoc as we know it, but you can make your own to generate code or other documentation formats.
There are 3 popular parser generators, all written in Java themselves, which have Java grammars already available: Antlr (on antlr.org), SableCC (on sablecc.org) and JavaCC (on dev.java.net). Those would simplify the job significantly.