Record Class AggregateMetrics

java.lang.Object
java.lang.Record
org.ek9lang.compiler.ir.data.AggregateMetrics
Record Components:
cohesion - LCOM4 cohesion (0.0 low to 1.0 high)
coupling - CBO coupling (number of coupled classes)
inheritanceDepth - DIT inheritance depth
methodCount - Number of methods (or WMC weighted count)

public record AggregateMetrics(double cohesion, int coupling, int inheritanceDepth, int methodCount) extends Record
Code quality metrics for a class, record, or component.

Object-oriented metrics that most tools ignore but are valuable for identifying refactoring candidates. These metrics are UNIQUE to EK9 coverage reports - competitors like JaCoCo don't offer them.

Metric definitions:

  • LCOM4 (Lack of Cohesion of Methods): 0.0 = poor cohesion, 1.0 = perfect cohesion
  • CBO (Coupling Between Objects): Count of classes this class depends on
  • DIT (Depth of Inheritance Tree): How deep in inheritance hierarchy
  • WMC (Weighted Methods per Class): Sum of method complexities
  • Field Details

    • EMPTY

      public static final AggregateMetrics EMPTY
      Empty metrics for aggregates without collected data.
  • Constructor Details

    • AggregateMetrics

      public AggregateMetrics(double cohesion, int coupling, int inheritanceDepth, int methodCount)
      Creates an instance of a AggregateMetrics record class.
      Parameters:
      cohesion - the value for the cohesion record component
      coupling - the value for the coupling record component
      inheritanceDepth - the value for the inheritanceDepth record component
      methodCount - the value for the methodCount record component
  • Method Details

    • hasLowCohesion

      public boolean hasLowCohesion()
      Check if cohesion is below acceptable threshold.

      LCOM4 < 0.5 indicates poor cohesion - the class is likely doing too many unrelated things and should be split.

      Returns:
      true if cohesion is poor (but data exists)
    • hasHighCoupling

      public boolean hasHighCoupling()
      Check if coupling is above acceptable threshold.

      CBO > 10 indicates high coupling - the class depends on too many other classes, making it fragile to changes.

      Returns:
      true if coupling is too high
    • hasDeepInheritance

      public boolean hasDeepInheritance()
      Check if inheritance is too deep.

      DIT > 5 may indicate over-engineering or poor design. Deep hierarchies are hard to understand and maintain.

      Returns:
      true if inheritance is too deep
    • needsAttention

      public boolean needsAttention()
      Check if this aggregate needs attention based on any metric.
      Returns:
      true if any metric indicates a problem
    • cohesionInterpretation

      @Nonnull public String cohesionInterpretation()
      Get cohesion interpretation for display.
      Returns:
      human-readable cohesion assessment
    • couplingInterpretation

      @Nonnull public String couplingInterpretation()
      Get coupling interpretation for display.
      Returns:
      human-readable coupling assessment
    • hasData

      public boolean hasData()
      Check if this record has any meaningful data.
      Returns:
      true if any metric has data
    • toString

      @Nonnull public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • cohesion

      public double cohesion()
      Returns the value of the cohesion record component.
      Returns:
      the value of the cohesion record component
    • coupling

      public int coupling()
      Returns the value of the coupling record component.
      Returns:
      the value of the coupling record component
    • inheritanceDepth

      public int inheritanceDepth()
      Returns the value of the inheritanceDepth record component.
      Returns:
      the value of the inheritanceDepth record component
    • methodCount

      public int methodCount()
      Returns the value of the methodCount record component.
      Returns:
      the value of the methodCount record component