I was recently tasked with finding out the number of methods in each class in each package inside of OpenMRS. My first thought was to write a java class to do some reflection. My second thought was to find a java class that someone else had written and use that. My third thought was to find a way for Eclipse to do it.
I really should have jumped to that last one first. Googling for my second thought gave me nothing useful. However, simply adding “eclipse” to my search term brought up the Metrics plugin as the first result! The Metrics plugin counts all different types of things. Lucky for me, “number of methods” just happens to be one of them.
To get the counts working for you, follow these easy steps:
- Add http://metrics.sourceforge.net/update to eclipse as a plugin update site
- Turn metrics on for your project:
- Right click on the root of your project in Package Explorer view
- Choose Properties–>Metrics–>Enable Metrics
- Do an Eclipse clean rebuild
- Click on the root of your project in the Package Explorer
- Open the “Metrics” view
These are the relevant statistics from the OpenMRS project:
The second api/web are from the test package. We have a lot of work to do to catch our total number of unit test methods up with our number of api methods.
I’ve also uploaded the entire OpenMRS metrics output.