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 scoreinjectionCount- Number of DI injection variables (BANG declarations) in this functioncouplingCount- Efferent coupling (Ce): distinct external types this construct depends on. A TYPE-level property inherited by each of its operations.couplingLimit- The genus-specific Ce ceiling this construct was checked against, carried alongside the count so consumers can form the ratio without a genusdefaulted- Whether the compiler generated this operation's body (adefaultoperator or constructor) rather than the author writing one. Provenance, not a measurement — which is why it rides here rather than being inferred downstream from "cognitive 0", a test every trivial hand-written member also passes. A generated body is not an editable site, so change-risk must never NAME it as the worst construct; its coupling is nonetheless real (the generated fold genuinely touches every field type), so it is still scored. SeeConstructHexReport.worst().pure- Whether the operation is markedas pure. Carried for REPORTING only — it feeds no score. Purity bounds how damage travels (a pure construct can only reach its callers, an impure one can also reach code through mutated state) rather than whether the code can be wrong, so it does not belong in a hazard built from complexity and coupling. Its intended use is qualifying afferent coupling: for a pure construct Ca is a complete blast radius, for an impure one it is a lower bound. Emitted now so that reading can be calibrated against real codebases before any scoring rule is committed to.identity- The construct's JOIN KEY (Aggregate.member, or a bare name for a free function) —CoverageDisplayName.identityForSymbol. Distinct from the display name carried alongside it, which renders a constructor bare and so cannot be matched against any other producer's naming. Null only for callers with no symbol to resolve.
public record FunctionMetrics(int cyclomaticComplexity, int cognitiveComplexity, int nestingDepth, int statementCount, int expressionComplexity, int injectionCount, int couplingCount, int couplingLimit, boolean defaulted, boolean pure, String identity)
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, int injectionCount, int couplingCount, int couplingLimit, boolean defaulted, boolean pure, String identity) Creates an instance of aFunctionMetricsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the value of thecognitiveComplexityrecord component.intReturns the value of thecouplingCountrecord component.intReturns the value of thecouplingLimitrecord component.intReturns the value of thecyclomaticComplexityrecord component.booleanReturns the value of thedefaultedrecord 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.identity()Returns the value of theidentityrecord component.intReturns the value of theinjectionCountrecord component.booleanCheck if this function needs attention based on any metric.intReturns the value of thenestingDepthrecord component.booleanpure()Returns the value of thepurerecord 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, int injectionCount, int couplingCount, int couplingLimit, boolean defaulted, boolean pure, String identity) 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 componentinjectionCount- the value for theinjectionCountrecord componentcouplingCount- the value for thecouplingCountrecord componentcouplingLimit- the value for thecouplingLimitrecord componentdefaulted- the value for thedefaultedrecord componentpure- the value for thepurerecord componentidentity- the value for theidentityrecord 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. Reference components are compared withObjects::equals(Object,Object); primitive components 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
-
injectionCount
public int injectionCount()Returns the value of theinjectionCountrecord component.- Returns:
- the value of the
injectionCountrecord component
-
couplingCount
public int couplingCount()Returns the value of thecouplingCountrecord component.- Returns:
- the value of the
couplingCountrecord component
-
couplingLimit
public int couplingLimit()Returns the value of thecouplingLimitrecord component.- Returns:
- the value of the
couplingLimitrecord component
-
defaulted
-
pure
-
identity
-