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
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.
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.
Oh, JavaParser sounds interesting. It does look a bit heavy-weight, but I’ll give it a try. Thanks!
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!
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!