Class MethodVariantSupport

java.lang.Object
org.apache.groovy.contracts.MethodVariantSupport

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

    • enter

      public static Object enter(String key, String className, Object measure)
      Record this invocation's measure for key (unless disabled for className by -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 a RecursionVariantViolation otherwise. Returns the value exit(java.lang.String, java.lang.Object) must restore.
      Parameters:
      key - the method's signature key
      className - the declaring class name (for -ea/-da gating)
      measure - the measure value for this invocation
      Returns:
      the enclosing invocation's measure, null if outermost, or a disabled sentinel
    • exit

      public static void exit(String key, Object prev)
      Restore the enclosing invocation's measure on return from key (a no-op when checks were disabled).
      Parameters:
      key - the method's signature key
      prev - the value returned by the matching enter(java.lang.String, java.lang.String, java.lang.Object) call