public class TypeConverterFactory extends Object
LinkerServices.asType(MethodHandle, MethodType)
. It manages the known GuardingTypeConverterFactory
instances and creates appropriate converters for method handles.Constructor and Description |
---|
TypeConverterFactory(Iterable<? extends GuardingTypeConverterFactory> factories)
Creates a new type converter factory from the available
GuardingTypeConverterFactory instances. |
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.
|
MethodHandle |
getTypeConverter(Class<?> sourceType,
Class<?> targetType)
Given a source and target type, returns a method handle that converts between them.
|
public TypeConverterFactory(Iterable<? extends GuardingTypeConverterFactory> factories)
GuardingTypeConverterFactory
instances.factories
- the GuardingTypeConverterFactory
instances to compose.public 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.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 boolean 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 conversionpublic ConversionComparator.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.public MethodHandle getTypeConverter(Class<?> sourceType, Class<?> targetType)
sourceType
- the type to convert fromtargetType
- the type to convert toCopyright © 2015 Attila Szegedi. All rights reserved.