Package com.tnsai.actions.contracts
Class ContractEvaluator
java.lang.Object
com.tnsai.actions.contracts.ContractEvaluator
Evaluates
@Contract expressions with Apache Commons JEXL (TNS-552).
JEXL was chosen over SpEL (needs Spring), MVEL (less maintained), and a
custom interpreter (insufficient for method calls / null-safe navigation). It
is a standalone, Apache-2.0 expression engine supporting the comparison,
arithmetic, method-invocation and null-safe-navigation that contract clauses
need (amount > 0, account.balance >= amount,
result.success()).
Engine config: strict (an undefined variable throws rather than
silently resolving to null — a contract referencing a typo'd parameter is a
bug we want surfaced, not a silent pass). Parsed JexlExpressions are
cached by source string since contract clauses are fixed and re-evaluated on
every action invocation.
- Since:
- 0.11.0
- Author:
- TnsAI Team
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckSyntax(String expression) Parses an expression without evaluating it — used by the build-time validator (AGENT-V013) to catch syntax errors early.booleanevaluateBoolean(String expression, Map<String, Object> bindings) Evaluates a boolean contract expression against the given bindings.evaluateValue(String expression, Map<String, Object> bindings) Evaluates an arbitrary expression to its value (used forold(...)snapshots).
-
Constructor Details
-
ContractEvaluator
public ContractEvaluator()
-
-
Method Details
-
evaluateBoolean
Evaluates a boolean contract expression against the given bindings.- Throws:
IllegalStateException- if the expression does not evaluate to a booleanorg.apache.commons.jexl3.JexlException- on evaluation error (undefined var, bad navigation)
-
evaluateValue
Evaluates an arbitrary expression to its value (used forold(...)snapshots). -
checkSyntax
Parses an expression without evaluating it — used by the build-time validator (AGENT-V013) to catch syntax errors early.- Throws:
org.apache.commons.jexl3.JexlException- on a parse error
-