简体   繁体   中英

Using java reflection for static code analysis

I am developing a static code dependency analysis tool where I plan to read .java files into a Class/interface/etc objects and then build logic around its properties using public methods such as:

Class.getImports();

etc. Are there any existing libraries such as Java Reflection that can parse java files that belong to external projects into a Class/Enum/etc object?

The Class/Interface/etc. objects represent instances of the corresponding objects loaded into an actual Java virtual machine. They cannot be used to represent code in .java files, because the Java reflection APIs are final classes, not interfaces, and therefore cannot have alternative implementations.

To analyze .java files, you can use other APIs such as the Java compiler tree API .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM