aspose file tools*
The moose likes Java in General and the fly likes Cyclomatic Complexity Calculation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cyclomatic Complexity Calculation" Watch "Cyclomatic Complexity Calculation" New topic
Author

Cyclomatic Complexity Calculation

vikram solanki
Greenhorn

Joined: Dec 07, 2010
Posts: 12
Hi

I was trying to find the cyclomatic complexity (CC) of a Java program and i am having a few problems. i tried generating CCby using the below code...



but i don't think this is right... because i am not taking into account the nested ifs and for loops and i feel not all parameters have been added. How exactly are the nested if's and for's should be considered...
Also i need the average CC of the program... now is the average complexity (total CC / Number of methods)? when i calculated the avg CC of the below attached Java file i found it to be 2.26 but when i generated it through a tool i got the value as 1.6. Also do method calls come into account for CC
can anyone please tell me how exactly to deal with this??

Thanks
vikram solanki
Greenhorn

Joined: Dec 07, 2010
Posts: 12
The Java File that i tested for CC is given below...



Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
Not an answer to your question, but be aware that the code does not seem to ignore keywords that occur in comments and string literals. You're most likely better off using a proper Java source code parser, like those that are available for Antlr, JavaCC and SableCC.

Also note that "foreach", "or", "and" and "xor" are not Java keywords.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

And neither is elseif.
Dan Be
Greenhorn

Joined: Feb 14, 2011
Posts: 1
This article may help you find what you are looking for: http://www.mccabe.com/iq_research_nist.htm
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cyclomatic Complexity Calculation