Class CouplingTracker

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

class CouplingTracker extends Object
Tracks efferent coupling (Ce) - the number of external types a construct depends on. Based on CBO (Coupling Between Objects) from Chidamber & Kemerer (1994).

Uses a stack to handle nested constructs (e.g., inner classes). Built-in types from org.ek9.lang are excluded from the count as they are universal primitives that don't contribute to meaningful coupling.

Complexity: O(T) where T = total type references - linear, not N-squared.

  • Constructor Details

    • CouplingTracker

      CouplingTracker()
  • Method Details

    • pushScope

      void pushScope()
      Push a new scope for tracking coupling of a construct.
    • recordDependency

      void recordDependency(ISymbol type)
      Record a type dependency. Unwraps generics and filters out built-in types.

      A field/param/return typed Optional of domain::Address architecturally couples to domain::Address, not to the built-in Optional container it is created inside. A naive outer-FQN read attributes the coupling to org.ek9.lang and the real target vanishes — the generics-hole that made E11015 evadable through any generic. So each reference is decomposed via GenericTypeInfo: the generic template (empty for a plain type; the built-in container for List/Dict/Optional, filtered below; a user Cache's own module for a user generic) plus every leaf concrete type argument, recursively. This is the SAME decomposition the MCP architecture tools measure with, so the enforced count and the measured count agree by construction.

      Parameters:
      type - the symbol representing the dependent type
    • recordDelegation

      void recordDelegation()
      Record that the current construct delegates a trait via by — worth a 0.5 discount on its efferent coupling. Safe to call when no scope is open (ignored).
    • popAndGetCouplingCount

      double popAndGetCouplingCount()
      Pop the current scope and return the (delegation-weighted) coupling count.
      Returns:
      the fractional efferent coupling — whole unless the construct uses by delegation
    • isEmpty

      boolean isEmpty()
      Check if there are any scopes being tracked.
      Returns:
      true if no scopes are on the stack