Package org.apache.groovy.contracts
Class MethodVariantSupport
java.lang.Object
org.apache.groovy.contracts.MethodVariantSupport
Runtime support for a method-level
Decreases recursion
termination measure. Code generated by
MethodVariantASTTransformation wraps the
method body so that on entry enter(java.lang.String, java.lang.String, java.lang.Object) records the measure (keyed by method
signature, per thread) and, when the method is already on the stack — i.e. this
is a recursive re-entry — checks that the measure strictly decreased and is
non-negative. exit(java.lang.String, java.lang.Object) restores the enclosing frame's value on return.
Because the check is pure entry/exit bookkeeping it needs no static analysis of recursive call sites: any re-entry of the same method (direct, mutual, or via a callback) is compared against its nearest enclosing frame.
- Since:
- 6.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectRecord this invocation's measure forkey(unless disabled forclassNameby-ea/-da).static voidRestore the enclosing invocation's measure on return fromkey(a no-op when checks were disabled).
-
Method Details
-
enter
Record this invocation's measure forkey(unless disabled forclassNameby-ea/-da). If an enclosing invocation of the same method is already active — a recursive re-entry — verify the measure strictly decreased and remained non-negative, raising aRecursionVariantViolationotherwise. Returns the valueexit(java.lang.String, java.lang.Object)must restore.- Parameters:
key- the method's signature keyclassName- the declaring class name (for-ea/-dagating)measure- the measure value for this invocation- Returns:
- the enclosing invocation's measure,
nullif outermost, or a disabled sentinel
-
exit
Restore the enclosing invocation's measure on return fromkey(a no-op when checks were disabled).- Parameters:
key- the method's signature keyprev- the value returned by the matchingenter(java.lang.String, java.lang.String, java.lang.Object)call
-