code that takes in a Java file and outputs the names of the classes and methods?
I was wondering if anyone out there had code which takes in a .java
file, and outputs the class names within that file, and the method
names and their arguments?
If not, can anybody give me advice on how to approach this problem?
- I've written a .class file disassembler which will output class and
method information. This can be found at
http://www.bearcave.com/software/java/javad/index.html. If you want
to go from source, you might start with the ANTLR Java parser. You
can build abstract syntax trees for the Java class information and
then output this.
- --- In email@example.com, iank@b... wrote:
> I've written a .class file disassembler which will output class
> method information. This can be found atwant
> http://www.bearcave.com/software/java/javad/index.html. If you
> to go from source, you might start with the ANTLR Java parser.You
> can build abstract syntax trees for the Java class information andHi,
> then output this.
Thanks for that info. I have the Abstract Syntax Tree in memory and
was wondering what the easiest way to extract the class and method
information from this? Would it just be a case of calling getChild()
and getNextSibling() recursively, and looking for class and method
names? Alternatively, could I look though the string representation
of the tree for all the class and method types?
Is there a set algorithm for going through all the nodes in an AST,
as I'm having trouble getting my head round it! I don't think I have
time to implement a tree parser, so I have to use getFirstChild() and
getNextSibling() when walking the tree...
Any help would be greatly appreciated, (dissertation handin is very
- It should be possible to only build abstract syntax tree productions
for the syntax you are interested in. For example, the class name
and methods. When the production for the class finishes, you can
then output output the class skeleton.
In building the syntax tree, I'd just build my own, rather than
spending the time to learn the ANTLR tree construction rules. But I
have some known biases here.