Class ContractEvaluator

java.lang.Object
com.tnsai.actions.contracts.ContractEvaluator

public final class ContractEvaluator extends Object
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 Details

    • ContractEvaluator

      public ContractEvaluator()
  • Method Details

    • evaluateBoolean

      public boolean evaluateBoolean(String expression, Map<String,Object> bindings)
      Evaluates a boolean contract expression against the given bindings.
      Throws:
      IllegalStateException - if the expression does not evaluate to a boolean
      org.apache.commons.jexl3.JexlException - on evaluation error (undefined var, bad navigation)
    • evaluateValue

      public Object evaluateValue(String expression, Map<String,Object> bindings)
      Evaluates an arbitrary expression to its value (used for old(...) snapshots).
    • checkSyntax

      public void checkSyntax(String expression)
      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