• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Analysing the content of a Java method

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

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?

Thanks,

Andy
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andy and welcome to Javaranch!

I'm actually going to shift this to another forum as there are plenty of third party tools that do this sort of thing for you
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).

I'd recommend looking for:

* Emma (code coverage)
* Clover (code coverage)
* PMD (code complexity)

Also have a search for java cyclomatic complexity on Google, hope that all helps!

Now that I've listed all of this without mentioning Ant or Maven I realise that I've moved it incorrectly, I'll send it back now.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
checkstyle/pmd pluggins are available ,they can be used to check the style,cyclometric complexity
 
Andy Young
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks,

Andy
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic