I am trying to look at the content of a Java method in order to analyse how "complex" it is. E.g. how many If, while, switch etc. statements there are. In addition to this, I would also like to know how many times a method is called from within a package (much like the Netbeans "Find Usages" functionality).
My initial idea is that I need to create a parser for the Java language (probably using ANTLR) though I'm not entirely sure this will do what I want. Can anyone advise me on this? Or know of any other way of analysing the content of a method?
Now it may seem a little strange that I've posted it to this forum, but the problem you describe is typically solved using various test and code coverage plugins/libraries that you can execute from Ant or Maven (and often also just the command line).
checkstyle/pmd pluggins are available ,they can be used to check the style,cyclometric complexity
Joined: Nov 03, 2008
Hi and thanks for your replies.
After googleing "java cyclomatic complexity" it appears that Cyvis will work nicely for me to look at how complex a method's content is.
As for the code coverage tools...something like Emma is not sufficient for what I am looking to do. Perhaps i should explain for thoroughly...
I want to write a Java program to analyse some given Java source code (from a different program) and work out which methods in that source code are called the most. Emma and Clover just state which parts of a running program were called (and i dont intend to run the source code i want to analyse). I would like to know how many places within the given source code call each of the methods in that source code (like the NetBeans "Find Usages" functionality when right-clicking a method). Any ideas?
Try Here for further 3rd party solutions. I use Cobertura as part of a Maven build and it definitely produces a number of times each line is called metric. [ November 03, 2008: Message edited by: Martijn Verburg ]