Class ProductionAssertionDetector
java.lang.Object
org.ek9lang.compiler.phase5.callgraph.ProductionAssertionDetector
Detects assertion statements that are reachable from non-test program entry points.
E81012: Production assertion - assertion reachable from non-test program
Assertions (assert, assertThrows, assertDoesNotThrow) are meant for TESTING only. Production code should use 'require' for precondition validation instead.
The distinction is semantic:
- assert: "This SHOULD be true during testing" (test validation)
- require: "This MUST be true in production" (precondition)
Having assertions in production code indicates confused intent and should be converted to 'require' statements or removed.
-
Constructor Summary
ConstructorsConstructorDescriptionProductionAssertionDetector(CallGraph callGraph, CallableErrorListenerLookup errorListenerLookup) Create a detector for assertions in production code. -
Method Summary
Modifier and TypeMethodDescriptionvoiddetect(Consumer<CallableInfo> consumer) Alternative API for just detection without error emission.Detect all assertions in production code and emit E81012 errors.Get the set of callables with assertions in production code.
-
Constructor Details
-
ProductionAssertionDetector
public ProductionAssertionDetector(CallGraph callGraph, CallableErrorListenerLookup errorListenerLookup) Create a detector for assertions in production code.- Parameters:
callGraph- The call graph with assertion and reachability informationerrorListenerLookup- Function to get ErrorListener for emitting errors
-
-
Method Details
-
detectAndReport
-
detect
Alternative API for just detection without error emission. Useful for testing and analysis.- Parameters:
consumer- Callback for each production assertion callable found
-
getAssertionsInProductionCode
-