Find out used classes and methods from Java source code

You need to use static analysis tool as STAN standalone mode:

The standalone application is targeted to architects and project managers who are typically not using the IDE.

Or JArchitect (available also using command line)

JArchitect is a powerful tool for static code analysis. It can provide a lot of insight into complex code bases. Using custom code queries you are able to build your own rule sets in a very comfortable way.

In the Class Browser right-click menu, JArchitect proposes to explore the graph of dependencies between members (methods + fields) of a type.

Another option is SourceTrail

The graph visualization provides a quick overview of any class, method, field, etc., of interest and all its relations. The graph is fully interactive. Use it to move through the codebase by focusing on related nodes and edges.


(source: sourcetrail.com)


Unfortunately, reflection doesn't give you all the information you need to do this.

I've done it with ASM (https://asm.ow2.io/).

It provides the ability to walk the byte code of all of your classes using the visitor pattern, including the actual method implementations, from which you can extract the references to other classes.

I'm sorry that I cannot provide the implementation, because it's proprietary.

Note that this works from your .jar files, not your sources. If you really need to work from sources, then have a look at https://github.com/javaparser . Really, though, it's better to use the byte code, since the java language changes frequently, while the byte code specification does not.

Tags:

Java