Class ComplexityCounter

java.lang.Object
org.ek9lang.compiler.phase5.ComplexityCounter

class ComplexityCounter extends Object
Designed to give a broad indication of complexity, this is not true pure Cyclometric Complexity. But it works on a region or code structure approach, looking at anything that may contribute to code being harder to read or taking more thought than just a simple sequence of statements. It takes into account boolean expressions, exception blocks and case statement for example.
  • Constructor Details

    • ComplexityCounter

      ComplexityCounter()
  • Method Details

    • push

      public AtomicInteger push()
      Push a zero value on to this stack.
    • push

      public AtomicInteger push(int initialValue)
      Push a zero value on to this stack.
    • peek

      public AtomicInteger peek()
      Take a look at the top of the stack.
    • pop

      Pop a region off the stack, returning BOTH its total complexity and the expression-complexity subtotal within it. Exception if empty.

      Returns both together on purpose: a separate popExpressionComplexity() would be an ordering hazard at the one call site, and the two stacks must be popped as a unit.

    • incrementComplexity

      public void incrementComplexity()
    • incrementComplexity

      public void incrementComplexity(AtomicInteger byValue)
    • incrementComplexity

      public void incrementComplexity(int byValue)
    • incrementExpressionComplexity

      public void incrementExpressionComplexity(int byValue)
      Record that byValue of the current region's complexity came from an EXPRESSION.

      Does NOT add to the total - the caller has already done that through incrementComplexity(int). This only retains the breakdown, which was previously lost.

    • isEmpty

      public boolean isEmpty()
      True if stack has no contents.