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 pathscognitiveComplexity- Cognitive complexity (SonarSource methodology) - mental effort to understandnestingDepth- Maximum nesting level of control structuresstatementCount- Number of statements in the functionexpressionComplexity- 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final FunctionMetricsEmpty metrics for functions without collected data. -
Constructor Summary
ConstructorsConstructorDescriptionFunctionMetrics(int cyclomaticComplexity, int cognitiveComplexity, int nestingDepth, int statementCount, int expressionComplexity) Creates an instance of aFunctionMetricsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the value of thecognitiveComplexityrecord component.intReturns the value of thecyclomaticComplexityrecord component.final booleanIndicates whether some other object is "equal to" this one.intReturns the value of theexpressionComplexityrecord component.booleanhasData()Check if this record has any meaningful data.final inthashCode()Returns a hash code value for this object.booleanCheck if cyclomatic or cognitive complexity exceeds recommended thresholds.booleanCheck if this function needs attention based on any metric.intReturns the value of thenestingDepthrecord component.Severity level for attention panel display.intReturns the value of thestatementCountrecord component.toString()Returns a string representation of this record class.
-
Field Details
-
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 aFunctionMetricsrecord class.- Parameters:
cyclomaticComplexity- the value for thecyclomaticComplexityrecord componentcognitiveComplexity- the value for thecognitiveComplexityrecord componentnestingDepth- the value for thenestingDepthrecord componentstatementCount- the value for thestatementCountrecord componentexpressionComplexity- the value for theexpressionComplexityrecord 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
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
-
hashCode
-
equals
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 thecomparemethod from their corresponding wrapper classes. -
cyclomaticComplexity
public int cyclomaticComplexity()Returns the value of thecyclomaticComplexityrecord component.- Returns:
- the value of the
cyclomaticComplexityrecord component
-
cognitiveComplexity
public int cognitiveComplexity()Returns the value of thecognitiveComplexityrecord component.- Returns:
- the value of the
cognitiveComplexityrecord component
-
nestingDepth
public int nestingDepth()Returns the value of thenestingDepthrecord component.- Returns:
- the value of the
nestingDepthrecord component
-
statementCount
public int statementCount()Returns the value of thestatementCountrecord component.- Returns:
- the value of the
statementCountrecord component
-
expressionComplexity
public int expressionComplexity()Returns the value of theexpressionComplexityrecord component.- Returns:
- the value of the
expressionComplexityrecord component
-