public class LinkerServicesImpl extends Object implements LinkerServices
LinkerServices interface.| Constructor and Description |
|---|
LinkerServicesImpl(TypeConverterFactory typeConverterFactory,
GuardingDynamicLinker topLevelLinker)
Creates a new linker services object.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.invoke.MethodHandle |
asType(java.lang.invoke.MethodHandle handle,
java.lang.invoke.MethodType fromType)
Similar to
MethodHandle.asType(MethodType) except it also hooks in method handles produced by
GuardingTypeConverterFactory implementations, providing for language-specific type coercing of
parameters. |
boolean |
canConvert(Class<?> from,
Class<?> to)
Returns true if there might exist a conversion between the requested types (either an automatic JVM conversion,
or one provided by any available
GuardingTypeConverterFactory), or false if there definitely does not
exist a conversion between the requested types. |
ConversionComparator.Comparison |
compareConversion(Class<?> sourceType,
Class<?> targetType1,
Class<?> targetType2)
Determines which of the two type conversions from a source type to the two target types is preferred.
|
GuardedInvocation |
getGuardedInvocation(LinkRequest linkRequest)
Creates a guarded invocation using the
DynamicLinker that exposes this linker services interface. |
java.lang.invoke.MethodHandle |
getTypeConverter(Class<?> sourceType,
Class<?> targetType)
Given a source and target type, returns a method handle that converts between them.
|
public LinkerServicesImpl(TypeConverterFactory typeConverterFactory, GuardingDynamicLinker topLevelLinker)
typeConverterFactory - the type converter factory exposed by the services.topLevelLinker - the top level linker used by the services.public boolean canConvert(Class<?> from, Class<?> to)
LinkerServicesGuardingTypeConverterFactory), or false if there definitely does not
exist a conversion between the requested types. Note that returning true does not guarantee that the conversion
will succeed at runtime (notably, if the "from" or "to" types are sufficiently generic), but returning false
guarantees that it would fail.canConvert in interface LinkerServicesfrom - the source type for the conversionto - the target type for the conversionpublic java.lang.invoke.MethodHandle asType(java.lang.invoke.MethodHandle handle, java.lang.invoke.MethodType fromType)
LinkerServicesMethodHandle.asType(MethodType) except it also hooks in method handles produced by
GuardingTypeConverterFactory implementations, providing for language-specific type coercing of
parameters. It will apply MethodHandle.asType(MethodType) for all primitive-to-primitive,
wrapper-to-primitive, primitive-to-wrapper conversions as well as for all upcasts. For all other conversions,
it'll insert MethodHandles.filterArguments(MethodHandle, int, MethodHandle...) with composite filters
provided by GuardingTypeConverterFactory implementations. It doesn't use language-specific conversions on
the return type.asType in interface LinkerServiceshandle - target method handlefromType - the types of source argumentsMethodHandle.asType(MethodType) and
MethodHandles.filterArguments(MethodHandle, int, MethodHandle...) with
GuardingTypeConverterFactory produced type converters as filters.public java.lang.invoke.MethodHandle getTypeConverter(Class<?> sourceType, Class<?> targetType)
LinkerServicesLinkerServices.asType(MethodHandle, MethodType) instead. You really
only need this method if you have a piece of your program that is written in Java, and you need to reuse existing
type conversion machinery in a non-invokedynamic context.getTypeConverter in interface LinkerServicessourceType - the type to convert fromtargetType - the type to convert topublic ConversionComparator.Comparison compareConversion(Class<?> sourceType, Class<?> targetType1, Class<?> targetType2)
LinkerServicesConversionComparators are consulted.compareConversion in interface LinkerServicessourceType - the source type.targetType1 - one potential target typetargetType2 - another potential target type.public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest) throws Exception
LinkerServicesDynamicLinker that exposes this linker services interface. Linkers
can typically use them to delegate linking of wrapped objects.getGuardedInvocation in interface LinkerServiceslinkRequest - a request for linking the invocationException - in case the top-level linker throws an exceptionCopyright © 2013 Attila Szegedi. All Rights Reserved.