How can I extract class symbols from a Java codebase?

0
1
Asked By CuriousCoder42 On

I'm currently working on a personal project aimed at visualizing a large Java code base. My initial task is to extract specific details from a Java source file, including the class name, class members, constructors with parameters, class functions with their parameters and return types, and usages of class members within these functions. While I'm building a parser from scratch for this, I'm curious if there's an existing tool that can scan through multiple files in a codebase and generate a JSON or text file containing all this information.

3 Answers

Answered By CodeExplorer99 On

You might want to check out ctags; it can handle the first four extraction tasks. However, for identifying member usages consistently, you’d probably need some type inference capabilities which it doesn’t provide. If you can compile the source code, extracting data from the compiled class files might be simpler since member usages would be fully resolved then.

CuriousCoder42 -

Yes! I can compile the source code. Is there a tool that can give me this information from the class files? That would really help!

Answered By JavaWhizKid On

Take a look at JavaParser. It's specifically designed to parse Java source code and should work for your needs. If you need to get symbols during the compile process, consider writing a Java compiler plugin. Alternatively, libraries like ASM or ByteBuddy could help you analyze compiled class files without needing the original source.

CuriousCoder42 -

Oh, JavaParser sounds interesting. It does look a bit heavy-weight, but I’ll give it a try. Thanks!

Answered By DevGuru101 On

Eclipse JDT might be what you need. It allows you to browse through Java projects, extracting details about packages, classes, and methods. You should be able to use it to export this information in JSON format, although the documentation can be a bit sparse. You might find useful examples online to get started!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.