Search code examples
javaintellij-ideatime-complexityintellij-plugincyclomatic-complexity

Cyclomatic Complexity in Intellij


I was working on an assignment today that basically asked us to write a Java program that checks if HTML syntax is valid in a text file. Pretty simple assignment, I did it very quickly, but in doing it so quickly I made it very convoluted (lots of loops and if statements). I know I can make it a lot simpler, and I will before turning it in, but Amid my procrastination, I started downloading plugins and seeing what information they could give me.

I downloaded two in particular that I'm curious about - CodeMetrics and MetricsReloaded. I was wondering what exactly these numbers that it generates correlate to. I saw one post that was semi-similar, and I read it as well as the linked articles, but I'm still having some trouble understanding a couple of things. Namely, what the first two columns (CogC and ev(G)), as well as some more clarification on the other two (iv(G) and v(G)), mean.

MetricsReloaded Method Metrics:

MetricsReloaded Method Metrics

MetricsReloaded Class Metrics:

MetricsReloaded Class Metrics

These previous numbers are from MetricsReloaded, but this other application, CodeMetrics, which also calculates cyclomatic complexity gives slightly different numbers. I was wondering how these numbers correlate and if someone could just give a brief general explanation of all this.

CodeMetrics Analysis Results:

CodeMetrics Analysis Results

My final question is about time complexity. My understanding of Cyclomatic complexity is that it is the number of possible paths of execution and that it is determined by the number of conditionals and how they are nested. It doesn't seem like it would, but does this correlate in any way to time complexity? And if so, is there a conversion between them that can be easily done? If not, is there a way in either of these plug-ins (or any other in IntelliJ) that can automate time complexity calculations?


Solution

  • To answer you first question here is the definition of those metrics in question

    • CogC - Cognitive complexity is essential for controlling and confirming high degrees of software maintainability which often involves software change.

    • ev(G) - Essential Complexity Metric is a measure of the degree to which a module contains unstructured constructs. This metric measures the degree of structuredness and the quality of the code. It is used to predict the maintenance effort and to help in the modularization process.

    • iv(G) - Module Design Complexity Metric is the complexity of the design-reduced module and reflects the complexity of the module's calling patterns to its immediate subordinate modules. This metric differentiates between modules which will seriously complicate the design of any program they are part of and modules which simply contain complex computational logic.

    • v(G) - Cyclomatic Complexity is a measure of the complexity of a module's decision structure. It is the number of linearly independent paths and therefore, the minimum number of paths that should be tested.

    Sources:

    https://www.sciencedirect.com/science/article/abs/pii/S0950584918301903 http://www.mccabe.com/iq_research_metrics.htm