Class ValueCoercibles

java.lang.Object
io.micronaut.context.python.ValueCoercibles

@Internal public final class ValueCoercibles extends Object
Recovers the generated ValueCoercible wrapper behind a polyglot value or proxy object, and matches Python arguments against Java parameter types for the runtime proxies.
Since:
5.2.0
Author:
Micronaut Team
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable ValueCoercible
    hostObject(@Nullable org.graalvm.polyglot.Value value)
    Extracts a generated Java wrapper from a polyglot value when one is available.
    static @Nullable Object
    hostObject(@Nullable org.graalvm.polyglot.Value value, Class<?> targetType)
    Extracts a host object of the requested type from a polyglot value.
    static @Nullable ValueCoercible
    hostObject(@Nullable org.graalvm.polyglot.proxy.ProxyObject value)
    Extracts a generated Java wrapper from a proxy object when one is available.
    static @Nullable Object
    hostObject(@Nullable org.graalvm.polyglot.proxy.ProxyObject value, Class<?> targetType)
    Extracts a host object of the requested type from a proxy object.
    static boolean
    matchesArgument(org.graalvm.polyglot.Value value, Class<?> targetType)
    Match one Python argument against a Java parameter type without conversion.

    Methods inherited from class Object

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

    • hostObject

      public static @Nullable ValueCoercible hostObject(@Nullable org.graalvm.polyglot.Value value)
      Extracts a generated Java wrapper from a polyglot value when one is available.

      This method recognizes both direct host objects and Micronaut's synthetic ValueCoercible.HOST_OBJECT_MEMBER back-reference.

      Parameters:
      value - The polyglot value to inspect.
      Returns:
      The generated wrapper, or null when the value is not backed by a ValueCoercible.
    • hostObject

      public static @Nullable ValueCoercible hostObject(@Nullable org.graalvm.polyglot.proxy.ProxyObject value)
      Extracts a generated Java wrapper from a proxy object when one is available.

      This overload is used when code already has a ProxyObject view and needs to inspect Micronaut's synthetic ValueCoercible.HOST_OBJECT_MEMBER without first wrapping it as a Value.

      Parameters:
      value - The proxy object to inspect.
      Returns:
      The generated wrapper, or null when the proxy does not expose one.
    • hostObject

      public static @Nullable Object hostObject(@Nullable org.graalvm.polyglot.Value value, Class<?> targetType)
      Extracts a host object of the requested type from a polyglot value.

      The returned object may be a direct GraalPy host object or the generated Java wrapper recovered through ValueCoercible.HOST_OBJECT_MEMBER.

      Parameters:
      value - The polyglot value to inspect.
      targetType - The required host object type.
      Returns:
      The host object when it is assignable to targetType; otherwise null.
    • hostObject

      public static @Nullable Object hostObject(@Nullable org.graalvm.polyglot.proxy.ProxyObject value, Class<?> targetType)
      Extracts a host object of the requested type from a proxy object.

      This method checks Micronaut's synthetic ValueCoercible.HOST_OBJECT_MEMBER and verifies the recovered host object before returning it.

      Parameters:
      value - The proxy object to inspect.
      targetType - The required host object type.
      Returns:
      The host object when it is assignable to targetType; otherwise null.
    • matchesArgument

      public static boolean matchesArgument(org.graalvm.polyglot.Value value, Class<?> targetType)
      Match one Python argument against a Java parameter type without conversion.

      Runtime proxies expose all overloads for a Java method name through one Python callable. This quick check uses generated ExecutableMethod metadata and only boxes primitive types through ReflectionUtils; it deliberately avoids reflective probing of the generated proxy class while still letting Python-backed values expose their host wrapper via ValueCoercible.HOST_OBJECT_MEMBER.

      Parameters:
      value - The Python argument
      targetType - The Java parameter type
      Returns:
      Whether the argument can be passed to the generated method