Package: org.apache.groovy.contracts

## [Java] Class MethodVariantSupport

- 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 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 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:
    Decreases
    RecursionVariantViolation

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static Object` | `enter(String key, String className, Object measure)` Record this invocation's measure for `key` (unless disabled for `className` by `-ea`/`-da`).
    `` | `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).

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### 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 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

    - #### 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 call