Record Class FunctionMetrics

java.lang.Object
java.lang.Record
org.ek9lang.compiler.ir.data.FunctionMetrics
Record Components:
cyclomaticComplexity - Cyclomatic complexity (McCabe) - number of linearly independent paths
cognitiveComplexity - Cognitive complexity (SonarSource methodology) - mental effort to understand
nestingDepth - Maximum nesting level of control structures
statementCount - Number of statements in the function
expressionComplexity - Expression complexity score

public record FunctionMetrics(int cyclomaticComplexity, int cognitiveComplexity, int nestingDepth, int statementCount, int expressionComplexity) extends Record
Code quality metrics for a single function/method.

Collected during Phase 5 (Pre-IR Checks) and passed through IR to coverage reports. Enables AI-assisted and human code quality analysis.

These metrics provide significant competitive advantage:

  • Cognitive complexity - SonarQube charges for this; EK9 includes it FREE
  • All metrics integrated with coverage - single unified report
  • Field Details

    • EMPTY

      public static final FunctionMetrics EMPTY
      Empty metrics for functions without collected data.
  • Constructor Details

    • FunctionMetrics

      public FunctionMetrics(int cyclomaticComplexity, int cognitiveComplexity, int nestingDepth, int statementCount, int expressionComplexity)
      Creates an instance of a FunctionMetrics record class.
      Parameters:
      cyclomaticComplexity - the value for the cyclomaticComplexity record component
      cognitiveComplexity - the value for the cognitiveComplexity record component
      nestingDepth - the value for the nestingDepth record component
      statementCount - the value for the statementCount record component
      expressionComplexity - the value for the expressionComplexity record component
  • Method Details

    • hasHighComplexity

      public boolean hasHighComplexity()
      Check if cyclomatic or cognitive complexity exceeds recommended thresholds.

      Thresholds based on industry standards:

      • Cyclomatic > 10: Function is complex
      • Cognitive > 15: Function is hard to understand
      Returns:
      true if either threshold is exceeded
    • needsAttention

      public boolean needsAttention()
      Check if this function needs attention based on any metric.

      Thresholds:

      • Cyclomatic > 15: Seriously complex
      • Cognitive > 25: Very hard to understand
      • Nesting > 4: Too deeply nested
      Returns:
      true if any threshold is exceeded
    • severityLevel

      @Nonnull public String severityLevel()
      Severity level for attention panel display.
      Returns:
      "critical" if CC > 20 or Cog > 30, "warning" if above thresholds, "ok" otherwise
    • hasData

      public boolean hasData()
      Check if this record has any meaningful data.
      Returns:
      true if any metric is non-zero
    • 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.
    • cyclomaticComplexity

      public int cyclomaticComplexity()
      Returns the value of the cyclomaticComplexity record component.
      Returns:
      the value of the cyclomaticComplexity record component
    • cognitiveComplexity

      public int cognitiveComplexity()
      Returns the value of the cognitiveComplexity record component.
      Returns:
      the value of the cognitiveComplexity record component
    • nestingDepth

      public int nestingDepth()
      Returns the value of the nestingDepth record component.
      Returns:
      the value of the nestingDepth record component
    • statementCount

      public int statementCount()
      Returns the value of the statementCount record component.
      Returns:
      the value of the statementCount record component
    • expressionComplexity

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