Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cyclomatic Complexity Calculation

 
vikram solanki
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java File that i tested for CC is given below...



 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6323
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And neither is elseif.
 
Dan Be
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article may help you find what you are looking for: http://www.mccabe.com/iq_research_nist.htm
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic