Class AcceptableModuleCohesionOrError

java.lang.Object
org.ek9lang.compiler.phase5.AcceptableModuleCohesionOrError
All Implemented Interfaces:
BiConsumer<String, List<ParsedModule>>

class AcceptableModuleCohesionOrError extends Object implements BiConsumer<String, List<ParsedModule>>
Validates module-level cohesion against threshold and emits E11017 error if exceeded. Unlike AcceptableCohesionOrError (construct-level LCOM4), this operates at the module level after all files in a module have been processed.

Module cohesion measures how well the constructs within a module relate to each other. Low cohesion (many disconnected groups) indicates a module that could be split into multiple focused modules.

Measurement: Connected component analysis using Union-Find (similar to LCOM4):

  • Each construct (class, record, trait, function) is a node
  • Each intra-module type reference is an edge
  • Count disconnected components - more components = lower cohesion

Threshold: Uses a hybrid approach - both absolute maximum AND percentage threshold must be exceeded:

  • Maximum 30 disconnected groups (absolute cap)
  • AND disconnected groups exceed 88% of total constructs (relative measure)

This allows legitimate modules with many independent utility constructs while catching truly fragmented modules that should be split.

Minimum constructs: 60 (smaller modules are not checked - only large modules warrant this check).

These thresholds are generous to accommodate EK9's functional style which encourages many small, pure functions that may not reference each other's types.