Class AcceptableCognitiveComplexityOrError

java.lang.Object
org.ek9lang.compiler.phase5.AcceptableCognitiveComplexityOrError
All Implemented Interfaces:
Consumer<org.antlr.v4.runtime.tree.ParseTree>

final class AcceptableCognitiveComplexityOrError extends Object implements Consumer<org.antlr.v4.runtime.tree.ParseTree>
Checks cognitive complexity at function/method/operator exit and emits error if too high. Cognitive complexity accounts for both nesting depth and EK9's unique guard expressions, providing a more accurate measure of how difficult code is to understand.

EK9's guards (<-) pack more cognitive load per line than simple conditions. A 6-level guarded structure is harder to understand than 6 simple ifs.

Threshold 35 allows:

  • Realistic production code while catching clearly abusive patterns
  • Simple nesting at depth 6 = 21 points (well under threshold)
  • Guarded nesting at depth 6 = 42 points (over threshold - needs refactoring)
See Also:
  • Constructor Details

  • Method Details

    • accept

      public void accept(org.antlr.v4.runtime.tree.ParseTree node)
      Specified by:
      accept in interface Consumer<org.antlr.v4.runtime.tree.ParseTree>