Class ModuleCohesionTracker
java.lang.Object
org.ek9lang.compiler.phase5.ModuleCohesionTracker
Tracks module-level cohesion by recording constructs and their intra-module type references.
Used to detect modules with low cohesion (disconnected construct groups that could be separate modules).
Thread-safe: designed to be used during parallel file processing where multiple PreIRListener instances (one per file) share a single ModuleCohesionTracker.
Cohesion is calculated using connected component analysis (Union-Find), similar to LCOM4:
- Nodes = constructs (classes, records, traits, functions) in the module
- Edges = intra-module type references (construct A references type B, both in same module)
- Connected components = groups of related constructs
- More components = lower cohesion = module should possibly be split
Based on package cohesion principles (Martin 2002 "Agile Software Development").
Complexity: O(C + R) where C = constructs, R = references - linear, not N-squared.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) intcalculateDisconnectedGroups(String moduleName) Calculate the number of disconnected construct groups in a module.(package private) intgetConstructCount(String moduleName) Get the count of constructs registered in a module.getConstructs(String moduleName) Get all constructs registered in a module (for tooling/diagnostics).Get all tracked module names.(package private) static booleanCheck if a module is exempt from module-level cohesion threshold checking.(package private) voidrecordReference(String moduleName, String fromConstructFqn, ISymbol referencedType) Record a type reference from one construct to another.(package private) voidregisterConstruct(String moduleName, String constructFqn) Register a construct (class, record, trait, function, etc.) as belonging to a module.
-
Constructor Details
-
ModuleCohesionTracker
ModuleCohesionTracker()
-
-
Method Details
-
registerConstruct
-
recordReference
Record a type reference from one construct to another. Only records if both constructs are in the same module (intra-module reference).- Parameters:
moduleName- the module being analyzedfromConstructFqn- the construct making the referencereferencedType- the type being referenced
-
calculateDisconnectedGroups
Calculate the number of disconnected construct groups in a module. Uses Union-Find algorithm for O(C * alpha(C)) complexity.This method is NOT thread-safe and should only be called during the sequential validation phase after all parallel file processing is complete.
- Parameters:
moduleName- the module to analyze- Returns:
- the number of disconnected groups (1 = fully cohesive, more = less cohesive)
-
getConstructCount
Get the count of constructs registered in a module.- Parameters:
moduleName- the module to check- Returns:
- count of constructs
-
getConstructs
-
getTrackedModules
-
isExempt
Check if a module is exempt from module-level cohesion threshold checking. Built-in modules (org.ek9.*) are exempt because they are utility modules by design.- Parameters:
moduleName- the module to check- Returns:
- true if exempt (built-in modules)
-