Java language statistics

I am interested in collecting statistics on the large body of Java code that I have access to. Some statistics that I’m interested in may include how often certain methods / classes are used, how often certain packages are imported, etc.

My first thought was to use javaparser , but this library only supports through Java 1.5, and most of the code I have is 1.6 or higher.

Is there a library that will give me the exact AST from some Java code (i.e. can I ask Javac for it somehow?), Or is there a better way to approach this problem (maybe study the bytecode)?

+5
source share
1 answer

I don’t know the exact AST, but you can certainly read byte codes using packages such as ASM or BCEL, and scanning these data structures for function calls would be quite simple. Of course, this can happen after some early optimization has been done, so it cannot directly reflect the source ... and it is before the JIT, therefore it cannot directly reflect what actually works.

Another solution would be to run code under the control of the profiler, which can give you either the relative or absolute frequency of the call from different places.

None of them would give you the amount of imports - this is a purely syntactically sugar detail. But for the same reason, I do not think this is a really significant number.

0
source

Source: https://habr.com/ru/post/1205325/


All Articles