Class ContractRuntime

java.lang.Object
media.barney.contract.runtime.ContractRuntime

@API(status=MAINTAINED) public final class ContractRuntime extends Object
Runtime support used by generated contract checks.

This class is part of the supported generated-code API. Application code normally declares contracts with media.barney.contract.Contract; annotation-processor-generated checks call this bridge to evaluate contracts and throw the documented exception types.

Object-valued bridge methods are null-safe. A null value is treated as passing because nullness is outside the contract model.

  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    requireParameterValue(byte value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    static void
    requireParameterValue(double value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    static void
    requireParameterValue(float value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    static void
    requireParameterValue(int value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    static void
    requireParameterValue(long value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    static void
    requireParameterValue(short value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    static void
    requireParameterValue(@Nullable Object value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated parameter contract with pre-resolved metadata.
    static byte
    requireReturnValue(byte value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    static double
    requireReturnValue(double value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    static float
    requireReturnValue(float value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    static int
    requireReturnValue(int value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    static long
    requireReturnValue(long value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    static short
    requireReturnValue(short value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    static <T extends @Nullable Object>
    T
    requireReturnValue(T value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
    Evaluates a generated return-value contract with pre-resolved metadata.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • requireParameterValue

      public static void requireParameterValue(@Nullable Object value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated parameter contract with pre-resolved metadata.

      Generated code calls this entry point with the runtime contract kind, message description, mask renderer, and attribute values that the annotation processor resolved from source annotations.

      Parameters:
      value - the parameter value to evaluate; null passes semantic contracts
      methodName - the fully qualified executable name used in messages
      parameterName - the parameter name used in messages
      contract - the contract kind to evaluate
      description - the generated or custom violation description
      customDescription - whether description came from a custom annotation message
      maskRenderer - renderer type for confidential values, or null when no masking applies
      min - numeric lower bound for range contracts
      max - numeric upper bound for range contracts
      minInclusive - whether the numeric lower bound is inclusive
      maxInclusive - whether the numeric upper bound is inclusive
      sizeMin - inclusive lower bound for size contracts
      sizeMax - inclusive upper bound for size contracts
      regexp - regular expression for pattern contracts
      Throws:
      IllegalArgumentException - when the parameter contract fails
    • requireParameterValue

      public static void requireParameterValue(byte value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    • requireParameterValue

      public static void requireParameterValue(short value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    • requireParameterValue

      public static void requireParameterValue(int value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    • requireParameterValue

      public static void requireParameterValue(long value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    • requireParameterValue

      public static void requireParameterValue(float value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    • requireParameterValue

      public static void requireParameterValue(double value, String methodName, String parameterName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated parameter contract without boxing a primitive value on the successful validation path.
    • requireReturnValue

      public static <T extends @Nullable Object> T requireReturnValue(T value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated return-value contract with pre-resolved metadata.

      Generated code calls this entry point with the runtime contract kind, message description, mask renderer, and attribute values that the annotation processor resolved from source annotations. The original value is returned unchanged when the contract passes so generated return statements can remain expression-shaped.

      Type Parameters:
      T - the return-value type
      Parameters:
      value - the return value to evaluate; null passes semantic contracts
      methodName - the fully qualified method name used in messages
      contract - the contract kind to evaluate
      description - the generated or custom violation description
      customDescription - whether description came from a custom annotation message
      maskRenderer - renderer type for confidential values, or null when no masking applies
      min - numeric lower bound for range contracts
      max - numeric upper bound for range contracts
      minInclusive - whether the numeric lower bound is inclusive
      maxInclusive - whether the numeric upper bound is inclusive
      sizeMin - inclusive lower bound for size contracts
      sizeMax - inclusive upper bound for size contracts
      regexp - regular expression for pattern contracts
      Returns:
      value when the contract passes
      Throws:
      IllegalStateException - when the return-value contract fails
    • requireReturnValue

      public static byte requireReturnValue(byte value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    • requireReturnValue

      public static short requireReturnValue(short value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    • requireReturnValue

      public static int requireReturnValue(int value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    • requireReturnValue

      public static long requireReturnValue(long value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    • requireReturnValue

      public static float requireReturnValue(float value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.
    • requireReturnValue

      public static double requireReturnValue(double value, String methodName, RuntimeContract contract, String description, boolean customDescription, @Nullable Class<? extends MaskRenderer> maskRenderer, long min, long max, boolean minInclusive, boolean maxInclusive, int sizeMin, int sizeMax, @Nullable String regexp)
      Evaluates a generated primitive return-value contract without boxing the value on the successful validation path.