Class MeasuredComplexity

java.lang.Object
org.ek9lang.compiler.support.MeasuredComplexity
All Implemented Interfaces:
ToIntFunction<ISymbol>

public final class MeasuredComplexity extends Object implements ToIntFunction<ISymbol>
THE tolerant reader for a symbol's measured CommonValues.COMPLEXITY, for consumers that treat "not measured" as zero rather than as an error.

Phase 5's AcceptableConstructComplexityOrError is the only thing that MEASURES complexity, and it is driven by parse-tree nodes. A synthesised method - a constrained type's cloned operator, a defaulted operator, a generated wrapper - has no parse tree node, so it is never visited and never measured. Consumers therefore have to cope with the value being absent.

Deliberately NOT used by the two strict readers. ComplexityDirectiveListener and AcceptableCombinedComplexitySizeOrError null-check and then parse raw, so a present-but-malformed value throws. That is the right behaviour for them - they are validating a value the compiler itself just wrote, and silently reading it as 0 would turn a compiler bug into a passing test. This class exists so the TOLERANT reading has one home rather than being re-derived per consumer; it is not an invitation to flatten those two onto it.

Its writer, for a synthesised construct phase 5 never visits, is MeasuredComplexityRecorder.

  • Constructor Details

    • MeasuredComplexity

      public MeasuredComplexity()
  • Method Details

    • applyAsInt

      public int applyAsInt(ISymbol symbol)
      The symbol's measured complexity, or 0 when it was never measured (or is unparseable).
      Specified by:
      applyAsInt in interface ToIntFunction<ISymbol>