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