Class ModuleCouplingTracker

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

class ModuleCouplingTracker extends Object
Tracks module-level efferent coupling (Ce) - the number of distinct external modules that a module depends on. Unlike CouplingTracker which counts external types per construct, this aggregates external module dependencies across all source files in a module.

Thread-safe: designed to be used during parallel file processing where multiple PreIRListener instances (one per file) share a single ModuleCouplingTracker.

Based on software architecture research (Martin 2002 "Agile Software Development") that recommends limiting dependencies between packages/modules to reduce fragility.

Complexity: O(R) where R = total type references across all files - linear, not N-squared.

  • Constructor Details

    • ModuleCouplingTracker

      ModuleCouplingTracker()
  • Method Details

    • recordDependency

      void recordDependency(String sourceModuleName, ISymbol referencedType)
      Record a type dependency for a specific module. Extracts the module name from the type and records if it's an external module.
      Parameters:
      sourceModuleName - the module where the reference occurs
      referencedType - the type being referenced
    • getExternalModuleCount

      int getExternalModuleCount(String moduleName)
      Get the count of external modules referenced by a specific module.
      Parameters:
      moduleName - the module to check
      Returns:
      count of distinct external modules
    • getExternalModules

      Set<String> getExternalModules(String moduleName)
      Get all external modules referenced by a specific module (for tooling/diagnostics).
      Parameters:
      moduleName - the module to check
      Returns:
      immutable set of external module names (may be empty, never null)
    • getTrackedModules

      Set<String> getTrackedModules()
      Get all tracked module names.
      Returns:
      immutable set of module names being tracked
    • isExempt

      static boolean isExempt(String moduleName)
      Check if a module is exempt from module-level coupling threshold checking. Built-in modules (org.ek9.*) are exempt because they have complex but intentional interdependencies that shouldn't be flagged as quality issues.
      Parameters:
      moduleName - the module to check
      Returns:
      true if exempt (built-in modules)