jdk.internal.dynalink.linker.ConversionComparator Java Examples

The following examples show how to use jdk.internal.dynalink.linker.ConversionComparator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeConverterFactory.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines which of the two type conversions from a source type to the two target types is preferred. This is
 * used for dynamic overloaded method resolution. If the source type is convertible to exactly one target type with
 * a method invocation conversion, it is chosen, otherwise available {@link ConversionComparator}s are consulted.
 * @param sourceType the source type.
 * @param targetType1 one potential target type
 * @param targetType2 another potential target type.
 * @return one of Comparison constants that establish which - if any - of the target types is preferable for the
 * conversion.
 */
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    for(final ConversionComparator comparator: comparators) {
        final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
        if(result != Comparison.INDETERMINATE) {
            return result;
        }
    }
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType1)) {
        if(!TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
            return Comparison.TYPE_1_BETTER;
        }
    } else if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #2
Source File: TypeConverterFactory.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines which of the two type conversions from a source type to the two target types is preferred. This is
 * used for dynamic overloaded method resolution. If the source type is convertible to exactly one target type with
 * a method invocation conversion, it is chosen, otherwise available {@link ConversionComparator}s are consulted.
 * @param sourceType the source type.
 * @param targetType1 one potential target type
 * @param targetType2 another potential target type.
 * @return one of Comparison constants that establish which - if any - of the target types is preferable for the
 * conversion.
 */
public Comparison compareConversion(Class<?> sourceType, Class<?> targetType1, Class<?> targetType2) {
    for(ConversionComparator comparator: comparators) {
        final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
        if(result != Comparison.INDETERMINATE) {
            return result;
        }
    }
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType1)) {
        if(!TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
            return Comparison.TYPE_1_BETTER;
        }
    } else if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #3
Source File: TypeConverterFactory.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines which of the two type conversions from a source type to the two target types is preferred. This is
 * used for dynamic overloaded method resolution. If the source type is convertible to exactly one target type with
 * a method invocation conversion, it is chosen, otherwise available {@link ConversionComparator}s are consulted.
 * @param sourceType the source type.
 * @param targetType1 one potential target type
 * @param targetType2 another potential target type.
 * @return one of Comparison constants that establish which - if any - of the target types is preferable for the
 * conversion.
 */
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    for(final ConversionComparator comparator: comparators) {
        final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
        if(result != Comparison.INDETERMINATE) {
            return result;
        }
    }
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType1)) {
        if(!TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
            return Comparison.TYPE_1_BETTER;
        }
    } else if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #4
Source File: TypeConverterFactory.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines which of the two type conversions from a source type to the two target types is preferred. This is
 * used for dynamic overloaded method resolution. If the source type is convertible to exactly one target type with
 * a method invocation conversion, it is chosen, otherwise available {@link ConversionComparator}s are consulted.
 * @param sourceType the source type.
 * @param targetType1 one potential target type
 * @param targetType2 another potential target type.
 * @return one of Comparison constants that establish which - if any - of the target types is preferable for the
 * conversion.
 */
public Comparison compareConversion(Class<?> sourceType, Class<?> targetType1, Class<?> targetType2) {
    for(ConversionComparator comparator: comparators) {
        final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
        if(result != Comparison.INDETERMINATE) {
            return result;
        }
    }
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType1)) {
        if(!TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
            return Comparison.TYPE_1_BETTER;
        }
    } else if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #5
Source File: TypeConverterFactory.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines which of the two type conversions from a source type to the two target types is preferred. This is
 * used for dynamic overloaded method resolution. If the source type is convertible to exactly one target type with
 * a method invocation conversion, it is chosen, otherwise available {@link ConversionComparator}s are consulted.
 * @param sourceType the source type.
 * @param targetType1 one potential target type
 * @param targetType2 another potential target type.
 * @return one of Comparison constants that establish which - if any - of the target types is preferable for the
 * conversion.
 */
public Comparison compareConversion(Class<?> sourceType, Class<?> targetType1, Class<?> targetType2) {
    for(ConversionComparator comparator: comparators) {
        final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
        if(result != Comparison.INDETERMINATE) {
            return result;
        }
    }
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType1)) {
        if(!TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
            return Comparison.TYPE_1_BETTER;
        }
    } else if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #6
Source File: TypeConverterFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines which of the two type conversions from a source type to the two target types is preferred. This is
 * used for dynamic overloaded method resolution. If the source type is convertible to exactly one target type with
 * a method invocation conversion, it is chosen, otherwise available {@link ConversionComparator}s are consulted.
 * @param sourceType the source type.
 * @param targetType1 one potential target type
 * @param targetType2 another potential target type.
 * @return one of Comparison constants that establish which - if any - of the target types is preferable for the
 * conversion.
 */
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    for(final ConversionComparator comparator: comparators) {
        final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
        if(result != Comparison.INDETERMINATE) {
            return result;
        }
    }
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType1)) {
        if(!TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
            return Comparison.TYPE_1_BETTER;
        }
    } else if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #7
Source File: TypeConverterFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines which of the two type conversions from a source type to the two target types is preferred. This is
 * used for dynamic overloaded method resolution. If the source type is convertible to exactly one target type with
 * a method invocation conversion, it is chosen, otherwise available {@link ConversionComparator}s are consulted.
 * @param sourceType the source type.
 * @param targetType1 one potential target type
 * @param targetType2 another potential target type.
 * @return one of Comparison constants that establish which - if any - of the target types is preferable for the
 * conversion.
 */
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    for(final ConversionComparator comparator: comparators) {
        final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
        if(result != Comparison.INDETERMINATE) {
            return result;
        }
    }
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType1)) {
        if(!TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
            return Comparison.TYPE_1_BETTER;
        }
    } else if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #8
Source File: TypeConverterFactory.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines which of the two type conversions from a source type to the two target types is preferred. This is
 * used for dynamic overloaded method resolution. If the source type is convertible to exactly one target type with
 * a method invocation conversion, it is chosen, otherwise available {@link ConversionComparator}s are consulted.
 * @param sourceType the source type.
 * @param targetType1 one potential target type
 * @param targetType2 another potential target type.
 * @return one of Comparison constants that establish which - if any - of the target types is preferable for the
 * conversion.
 */
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    for(final ConversionComparator comparator: comparators) {
        final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
        if(result != Comparison.INDETERMINATE) {
            return result;
        }
    }
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType1)) {
        if(!TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
            return Comparison.TYPE_1_BETTER;
        }
    } else if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #9
Source File: TypeConverterFactory.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines which of the two type conversions from a source type to the two target types is preferred. This is
 * used for dynamic overloaded method resolution. If the source type is convertible to exactly one target type with
 * a method invocation conversion, it is chosen, otherwise available {@link ConversionComparator}s are consulted.
 * @param sourceType the source type.
 * @param targetType1 one potential target type
 * @param targetType2 another potential target type.
 * @return one of Comparison constants that establish which - if any - of the target types is preferable for the
 * conversion.
 */
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    for(final ConversionComparator comparator: comparators) {
        final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
        if(result != Comparison.INDETERMINATE) {
            return result;
        }
    }
    if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType1)) {
        if(!TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
            return Comparison.TYPE_1_BETTER;
        }
    } else if(TypeUtilities.isMethodInvocationConvertible(sourceType, targetType2)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #10
Source File: TypeConverterFactory.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances.
 *
 * @param factories the {@link GuardingTypeConverterFactory} instances to compose.
 */
public TypeConverterFactory(Iterable<? extends GuardingTypeConverterFactory> factories) {
    final List<GuardingTypeConverterFactory> l = new LinkedList<>();
    final List<ConversionComparator> c = new LinkedList<>();
    for(GuardingTypeConverterFactory factory: factories) {
        l.add(factory);
        if(factory instanceof ConversionComparator) {
            c.add((ConversionComparator)factory);
        }
    }
    this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
    this.comparators = c.toArray(new ConversionComparator[c.size()]);

}
 
Example #11
Source File: TypeConverterFactory.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances.
 *
 * @param factories the {@link GuardingTypeConverterFactory} instances to compose.
 */
public TypeConverterFactory(Iterable<? extends GuardingTypeConverterFactory> factories) {
    final List<GuardingTypeConverterFactory> l = new LinkedList<>();
    final List<ConversionComparator> c = new LinkedList<>();
    for(GuardingTypeConverterFactory factory: factories) {
        l.add(factory);
        if(factory instanceof ConversionComparator) {
            c.add((ConversionComparator)factory);
        }
    }
    this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
    this.comparators = c.toArray(new ConversionComparator[c.size()]);

}
 
Example #12
Source File: TypeConverterFactory.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances.
 *
 * @param factories the {@link GuardingTypeConverterFactory} instances to compose.
 */
public TypeConverterFactory(Iterable<? extends GuardingTypeConverterFactory> factories) {
    final List<GuardingTypeConverterFactory> l = new LinkedList<>();
    final List<ConversionComparator> c = new LinkedList<>();
    for(GuardingTypeConverterFactory factory: factories) {
        l.add(factory);
        if(factory instanceof ConversionComparator) {
            c.add((ConversionComparator)factory);
        }
    }
    this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
    this.comparators = c.toArray(new ConversionComparator[c.size()]);

}
 
Example #13
Source File: TypeConverterFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances.
 *
 * @param factories the {@link GuardingTypeConverterFactory} instances to compose.
 * @param autoConversionStrategy conversion strategy for automatic type conversions. After
 * {@link #asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)} has applied all custom
 * conversions to a method handle, it still needs to effect
 * {@link TypeUtilities#isMethodInvocationConvertible(Class, Class) method invocation conversions} that
 * can usually be automatically applied as per
 * {@link java.lang.invoke.MethodHandle#asType(java.lang.invoke.MethodType)}.
 * However, sometimes language runtimes will want to customize even those conversions for their own call
 * sites. A typical example is allowing unboxing of null return values, which is by default prohibited by
 * ordinary {@code MethodHandles.asType}. In this case, a language runtime can install its own custom
 * automatic conversion strategy, that can deal with null values. Note that when the strategy's
 * {@link MethodTypeConversionStrategy#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)}
 * is invoked, the custom language conversions will already have been applied to the method handle, so by
 * design the difference between the handle's current method type and the desired final type will always
 * only be ones that can be subjected to method invocation conversions. Can be null, in which case no
 * custom strategy is employed.
 */
public TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories,
        final MethodTypeConversionStrategy autoConversionStrategy) {
    final List<GuardingTypeConverterFactory> l = new LinkedList<>();
    final List<ConversionComparator> c = new LinkedList<>();
    for(final GuardingTypeConverterFactory factory: factories) {
        l.add(factory);
        if(factory instanceof ConversionComparator) {
            c.add((ConversionComparator)factory);
        }
    }
    this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
    this.comparators = c.toArray(new ConversionComparator[c.size()]);
    this.autoConversionStrategy = autoConversionStrategy;
}
 
Example #14
Source File: TypeConverterFactory.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances.
 *
 * @param factories the {@link GuardingTypeConverterFactory} instances to compose.
 * @param autoConversionStrategy conversion strategy for automatic type conversions. After
 * {@link #asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)} has applied all custom
 * conversions to a method handle, it still needs to effect
 * {@link TypeUtilities#isMethodInvocationConvertible(Class, Class) method invocation conversions} that
 * can usually be automatically applied as per
 * {@link java.lang.invoke.MethodHandle#asType(java.lang.invoke.MethodType)}.
 * However, sometimes language runtimes will want to customize even those conversions for their own call
 * sites. A typical example is allowing unboxing of null return values, which is by default prohibited by
 * ordinary {@code MethodHandles.asType}. In this case, a language runtime can install its own custom
 * automatic conversion strategy, that can deal with null values. Note that when the strategy's
 * {@link MethodTypeConversionStrategy#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)}
 * is invoked, the custom language conversions will already have been applied to the method handle, so by
 * design the difference between the handle's current method type and the desired final type will always
 * only be ones that can be subjected to method invocation conversions. Can be null, in which case no
 * custom strategy is employed.
 */
public TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories,
        final MethodTypeConversionStrategy autoConversionStrategy) {
    final List<GuardingTypeConverterFactory> l = new LinkedList<>();
    final List<ConversionComparator> c = new LinkedList<>();
    for(final GuardingTypeConverterFactory factory: factories) {
        l.add(factory);
        if(factory instanceof ConversionComparator) {
            c.add((ConversionComparator)factory);
        }
    }
    this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
    this.comparators = c.toArray(new ConversionComparator[c.size()]);
    this.autoConversionStrategy = autoConversionStrategy;
}
 
Example #15
Source File: TypeConverterFactory.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances.
 *
 * @param factories the {@link GuardingTypeConverterFactory} instances to compose.
 * @param autoConversionStrategy conversion strategy for automatic type conversions. After
 * {@link #asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)} has applied all custom
 * conversions to a method handle, it still needs to effect
 * {@link TypeUtilities#isMethodInvocationConvertible(Class, Class) method invocation conversions} that
 * can usually be automatically applied as per
 * {@link java.lang.invoke.MethodHandle#asType(java.lang.invoke.MethodType)}.
 * However, sometimes language runtimes will want to customize even those conversions for their own call
 * sites. A typical example is allowing unboxing of null return values, which is by default prohibited by
 * ordinary {@code MethodHandles.asType}. In this case, a language runtime can install its own custom
 * automatic conversion strategy, that can deal with null values. Note that when the strategy's
 * {@link MethodTypeConversionStrategy#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)}
 * is invoked, the custom language conversions will already have been applied to the method handle, so by
 * design the difference between the handle's current method type and the desired final type will always
 * only be ones that can be subjected to method invocation conversions. Can be null, in which case no
 * custom strategy is employed.
 */
public TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories,
        final MethodTypeConversionStrategy autoConversionStrategy) {
    final List<GuardingTypeConverterFactory> l = new LinkedList<>();
    final List<ConversionComparator> c = new LinkedList<>();
    for(final GuardingTypeConverterFactory factory: factories) {
        l.add(factory);
        if(factory instanceof ConversionComparator) {
            c.add((ConversionComparator)factory);
        }
    }
    this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
    this.comparators = c.toArray(new ConversionComparator[c.size()]);
    this.autoConversionStrategy = autoConversionStrategy;
}
 
Example #16
Source File: TypeConverterFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances.
 *
 * @param factories the {@link GuardingTypeConverterFactory} instances to compose.
 * @param autoConversionStrategy conversion strategy for automatic type conversions. After
 * {@link #asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)} has applied all custom
 * conversions to a method handle, it still needs to effect
 * {@link TypeUtilities#isMethodInvocationConvertible(Class, Class) method invocation conversions} that
 * can usually be automatically applied as per
 * {@link java.lang.invoke.MethodHandle#asType(java.lang.invoke.MethodType)}.
 * However, sometimes language runtimes will want to customize even those conversions for their own call
 * sites. A typical example is allowing unboxing of null return values, which is by default prohibited by
 * ordinary {@code MethodHandles.asType}. In this case, a language runtime can install its own custom
 * automatic conversion strategy, that can deal with null values. Note that when the strategy's
 * {@link MethodTypeConversionStrategy#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)}
 * is invoked, the custom language conversions will already have been applied to the method handle, so by
 * design the difference between the handle's current method type and the desired final type will always
 * only be ones that can be subjected to method invocation conversions. Can be null, in which case no
 * custom strategy is employed.
 */
public TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories,
        final MethodTypeConversionStrategy autoConversionStrategy) {
    final List<GuardingTypeConverterFactory> l = new LinkedList<>();
    final List<ConversionComparator> c = new LinkedList<>();
    for(final GuardingTypeConverterFactory factory: factories) {
        l.add(factory);
        if(factory instanceof ConversionComparator) {
            c.add((ConversionComparator)factory);
        }
    }
    this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
    this.comparators = c.toArray(new ConversionComparator[c.size()]);
    this.autoConversionStrategy = autoConversionStrategy;
}
 
Example #17
Source File: TypeConverterFactory.java    From jdk8u_nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances.
 *
 * @param factories the {@link GuardingTypeConverterFactory} instances to compose.
 * @param autoConversionStrategy conversion strategy for automatic type conversions. After
 * {@link #asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)} has applied all custom
 * conversions to a method handle, it still needs to effect
 * {@link TypeUtilities#isMethodInvocationConvertible(Class, Class) method invocation conversions} that
 * can usually be automatically applied as per
 * {@link java.lang.invoke.MethodHandle#asType(java.lang.invoke.MethodType)}.
 * However, sometimes language runtimes will want to customize even those conversions for their own call
 * sites. A typical example is allowing unboxing of null return values, which is by default prohibited by
 * ordinary {@code MethodHandles.asType}. In this case, a language runtime can install its own custom
 * automatic conversion strategy, that can deal with null values. Note that when the strategy's
 * {@link MethodTypeConversionStrategy#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)}
 * is invoked, the custom language conversions will already have been applied to the method handle, so by
 * design the difference between the handle's current method type and the desired final type will always
 * only be ones that can be subjected to method invocation conversions. Can be null, in which case no
 * custom strategy is employed.
 */
public TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories,
        final MethodTypeConversionStrategy autoConversionStrategy) {
    final List<GuardingTypeConverterFactory> l = new LinkedList<>();
    final List<ConversionComparator> c = new LinkedList<>();
    for(final GuardingTypeConverterFactory factory: factories) {
        l.add(factory);
        if(factory instanceof ConversionComparator) {
            c.add((ConversionComparator)factory);
        }
    }
    this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
    this.comparators = c.toArray(new ConversionComparator[c.size()]);
    this.autoConversionStrategy = autoConversionStrategy;
}
 
Example #18
Source File: TypeConverterFactory.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances.
 *
 * @param factories the {@link GuardingTypeConverterFactory} instances to compose.
 * @param autoConversionStrategy conversion strategy for automatic type conversions. After
 * {@link #asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)} has applied all custom
 * conversions to a method handle, it still needs to effect
 * {@link TypeUtilities#isMethodInvocationConvertible(Class, Class) method invocation conversions} that
 * can usually be automatically applied as per
 * {@link java.lang.invoke.MethodHandle#asType(java.lang.invoke.MethodType)}.
 * However, sometimes language runtimes will want to customize even those conversions for their own call
 * sites. A typical example is allowing unboxing of null return values, which is by default prohibited by
 * ordinary {@code MethodHandles.asType}. In this case, a language runtime can install its own custom
 * automatic conversion strategy, that can deal with null values. Note that when the strategy's
 * {@link MethodTypeConversionStrategy#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)}
 * is invoked, the custom language conversions will already have been applied to the method handle, so by
 * design the difference between the handle's current method type and the desired final type will always
 * only be ones that can be subjected to method invocation conversions. Can be null, in which case no
 * custom strategy is employed.
 */
public TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories,
        final MethodTypeConversionStrategy autoConversionStrategy) {
    final List<GuardingTypeConverterFactory> l = new LinkedList<>();
    final List<ConversionComparator> c = new LinkedList<>();
    for(final GuardingTypeConverterFactory factory: factories) {
        l.add(factory);
        if(factory instanceof ConversionComparator) {
            c.add((ConversionComparator)factory);
        }
    }
    this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
    this.comparators = c.toArray(new ConversionComparator[c.size()]);
    this.autoConversionStrategy = autoConversionStrategy;
}