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 |
---|---|
MethodHandle |
asType(MethodHandle handle,
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. |
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)
LinkerServices
GuardingTypeConverterFactory
), 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 LinkerServices
from
- the source type for the conversionto
- the target type for the conversionpublic MethodHandle asType(MethodHandle handle, MethodType fromType)
LinkerServices
MethodHandle.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 LinkerServices
handle
- target method handlefromType
- the types of source argumentsMethodHandle.asType(MethodType)
and
MethodHandles.filterArguments(MethodHandle, int, MethodHandle...)
with
GuardingTypeConverterFactory
produced type converters as filters.public MethodHandle getTypeConverter(Class<?> sourceType, Class<?> targetType)
LinkerServices
LinkerServices.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 LinkerServices
sourceType
- the type to convert fromtargetType
- the type to convert topublic ConversionComparator.Comparison compareConversion(Class<?> sourceType, Class<?> targetType1, Class<?> targetType2)
LinkerServices
ConversionComparator
s are consulted.compareConversion
in interface LinkerServices
sourceType
- the source type.targetType1
- one potential target typetargetType2
- another potential target type.public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest) throws Exception
LinkerServices
DynamicLinker
that exposes this linker services interface. Linkers
can typically use them to delegate linking of wrapped objects.getGuardedInvocation
in interface LinkerServices
linkRequest
- a request for linking the invocationException
- in case the top-level linker throws an exceptionCopyright © 2019 Attila Szegedi. All rights reserved.