Class ValueCoercibles
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 TypeMethodDescriptionstatic @Nullable ValueCoerciblehostObject(@Nullable org.graalvm.polyglot.Value value) Extracts a generated Java wrapper from a polyglot value when one is available.static @Nullable ObjecthostObject(@Nullable org.graalvm.polyglot.Value value, Class<?> targetType) Extracts a host object of the requested type from a polyglot value.static @Nullable ValueCoerciblehostObject(@Nullable org.graalvm.polyglot.proxy.ProxyObject value) Extracts a generated Java wrapper from a proxy object when one is available.static @Nullable ObjecthostObject(@Nullable org.graalvm.polyglot.proxy.ProxyObject value, Class<?> targetType) Extracts a host object of the requested type from a proxy object.static booleanmatchesArgument(org.graalvm.polyglot.Value value, Class<?> targetType) Match one Python argument against a Java parameter type without conversion.
-
Method Details
-
hostObject
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_MEMBERback-reference.- Parameters:
value- The polyglot value to inspect.- Returns:
- The generated wrapper, or
nullwhen the value is not backed by aValueCoercible.
-
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
ProxyObjectview and needs to inspect Micronaut's syntheticValueCoercible.HOST_OBJECT_MEMBERwithout first wrapping it as aValue.- Parameters:
value- The proxy object to inspect.- Returns:
- The generated wrapper, or
nullwhen 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; otherwisenull.
-
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_MEMBERand 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; otherwisenull.
-
matchesArgument
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
ExecutableMethodmetadata and only boxes primitive types throughReflectionUtils; it deliberately avoids reflective probing of the generated proxy class while still letting Python-backed values expose their host wrapper viaValueCoercible.HOST_OBJECT_MEMBER.- Parameters:
value- The Python argumenttargetType- The Java parameter type- Returns:
- Whether the argument can be passed to the generated method
-