Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Cyclomatic Complexity Calculation

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java File that i tested for CC is given below...



 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 14327
321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And neither is elseif.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This article may help you find what you are looking for: http://www.mccabe.com/iq_research_nist.htm
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic