Record Class FileMetrics

java.lang.Object
java.lang.Record
org.ek9lang.compiler.ir.data.FileMetrics
Record Components:
readabilityScore - Human-readable grade (e.g., "10-11 Fifth Grade")
readabilityLevel - Numeric level (1-12+, lower is better)
totalLines - Total lines in file
codeLines - Lines containing code
commentLines - Lines containing comments
avgFunctionComplexity - Average cyclomatic complexity of functions in file
maxFunctionComplexity - Maximum cyclomatic complexity in file

public record FileMetrics(String readabilityScore, int readabilityLevel, int totalLines, int codeLines, int commentLines, double avgFunctionComplexity, int maxFunctionComplexity) extends Record
File-level metrics including ARI readability.

Associated with CompilableSource for per-file analysis. The ARI (Automated Readability Index) readability metric is UNIQUE to EK9 - no competitor offers source code readability analysis.

ARI has been adapted for source code by considering:

  • Identifier length (long names increase complexity)
  • Expression density (many operators reduce readability)
  • Indentation patterns (structure affects understanding)
  • Field Details

    • EMPTY

      public static final FileMetrics EMPTY
      Empty metrics for files without collected data.
  • Constructor Details

    • FileMetrics

      public FileMetrics(String readabilityScore, int readabilityLevel, int totalLines, int codeLines, int commentLines, double avgFunctionComplexity, int maxFunctionComplexity)
      Creates an instance of a FileMetrics record class.
      Parameters:
      readabilityScore - the value for the readabilityScore record component
      readabilityLevel - the value for the readabilityLevel record component
      totalLines - the value for the totalLines record component
      codeLines - the value for the codeLines record component
      commentLines - the value for the commentLines record component
      avgFunctionComplexity - the value for the avgFunctionComplexity record component
      maxFunctionComplexity - the value for the maxFunctionComplexity record component
  • Method Details

    • hasReadabilityIssue

      public boolean hasReadabilityIssue()
      Check if readability needs improvement.

      Level > 10 (11th grade reading level or above) indicates code that may be too complex for easy understanding.

      Returns:
      true if readability level exceeds threshold
    • commentRatio

      public double commentRatio()
      Get comment ratio (0.0 to 1.0).

      A ratio of 0.1-0.3 is typically healthy. Very low may indicate under-documented code. Very high may indicate code that's hard to understand without comments.

      Returns:
      ratio of comment lines to code lines
    • readabilityInterpretation

      @Nonnull public String readabilityInterpretation()
      Readability interpretation for display.
      Returns:
      human-readable assessment of readability
    • hasHighAverageComplexity

      public boolean hasHighAverageComplexity()
      Check if file has high average complexity.
      Returns:
      true if average function complexity > 10
    • hasVeryComplexFunctions

      public boolean hasVeryComplexFunctions()
      Check if file has very complex functions.
      Returns:
      true if max function complexity > 20
    • needsAttention

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

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

      @Nonnull public String readabilityCssClass()
      CSS class for readability status indicator.
      Returns:
      CSS class name for styling
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components 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.
    • readabilityScore

      public String readabilityScore()
      Returns the value of the readabilityScore record component.
      Returns:
      the value of the readabilityScore record component
    • readabilityLevel

      public int readabilityLevel()
      Returns the value of the readabilityLevel record component.
      Returns:
      the value of the readabilityLevel record component
    • totalLines

      public int totalLines()
      Returns the value of the totalLines record component.
      Returns:
      the value of the totalLines record component
    • codeLines

      public int codeLines()
      Returns the value of the codeLines record component.
      Returns:
      the value of the codeLines record component
    • commentLines

      public int commentLines()
      Returns the value of the commentLines record component.
      Returns:
      the value of the commentLines record component
    • avgFunctionComplexity

      public double avgFunctionComplexity()
      Returns the value of the avgFunctionComplexity record component.
      Returns:
      the value of the avgFunctionComplexity record component
    • maxFunctionComplexity

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