Java Code Examples for jdk.internal.dynalink.linker.ConversionComparator.Comparison

The following examples show how to use jdk.internal.dynalink.linker.ConversionComparator.Comparison. These examples are extracted from open source projects. 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 Project: TencentKona-8   Author: Tencent   File: TypeConverterFactory.java    License: 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 Project: jdk8u60   Author: chenghanpeng   File: TypeConverterFactory.java    License: 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 #3
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: TypeConverterFactory.java    License: 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 Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TypeConverterFactory.java    License: 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 #5
Source Project: hottub   Author: dsrg-uoft   File: TypeConverterFactory.java    License: 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 #6
Source Project: openjdk-8-source   Author: keerath   File: TypeConverterFactory.java    License: 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 #7
Source Project: openjdk-8   Author: bpupadhyaya   File: TypeConverterFactory.java    License: 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 #8
Source Project: jdk8u_nashorn   Author: JetBrains   File: TypeConverterFactory.java    License: 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 Project: nashorn   Author: ynsn   File: TypeConverterFactory.java    License: 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 #10
Source Project: TencentKona-8   Author: Tencent   File: NashornBeansLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if (sourceType == ConsString.class) {
        if (String.class == targetType1 || CharSequence.class == targetType1) {
            return Comparison.TYPE_1_BETTER;
        }

        if (String.class == targetType2 || CharSequence.class == targetType2) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return linkerServices.compareConversion(sourceType, targetType1, targetType2);
}
 
Example #11
Source Project: TencentKona-8   Author: Tencent   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison isMoreSpecific(final MethodType t1, final MethodType t2, final boolean varArgs, final Class<?>[] argTypes,
        final LinkerServices ls) {
    final int pc1 = t1.parameterCount();
    final int pc2 = t2.parameterCount();
    assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
    assert (argTypes == null) == (ls == null);
    final int maxPc = Math.max(Math.max(pc1, pc2), argTypes == null ? 0 : argTypes.length);
    boolean t1MoreSpecific = false;
    boolean t2MoreSpecific = false;
    // NOTE: Starting from 1 as overloaded method resolution doesn't depend on 0th element, which is the type of
    // 'this'. We're only dealing with instance methods here, not static methods. Actually, static methods will have
    // a fake 'this' of type StaticClass.
    for(int i = 1; i < maxPc; ++i) {
        final Class<?> c1 = getParameterClass(t1, pc1, i, varArgs);
        final Class<?> c2 = getParameterClass(t2, pc2, i, varArgs);
        if(c1 != c2) {
            final Comparison cmp = compare(c1, c2, argTypes, i, ls);
            if(cmp == Comparison.TYPE_1_BETTER && !t1MoreSpecific) {
                t1MoreSpecific = true;
                if(t2MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
            if(cmp == Comparison.TYPE_2_BETTER && !t2MoreSpecific) {
                t2MoreSpecific = true;
                if(t1MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
        }
    }
    if(t1MoreSpecific) {
        return Comparison.TYPE_1_BETTER;
    } else if(t2MoreSpecific) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #12
Source Project: TencentKona-8   Author: Tencent   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(final Class<?> c1, final Class<?> c2, final Class<?>[] argTypes, final int i, final LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #13
Source Project: jdk8u60   Author: chenghanpeng   File: NashornBeansLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if (sourceType == ConsString.class) {
        if (String.class == targetType1 || CharSequence.class == targetType1) {
            return Comparison.TYPE_1_BETTER;
        }

        if (String.class == targetType2 || CharSequence.class == targetType2) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return linkerServices.compareConversion(sourceType, targetType1, targetType2);
}
 
Example #14
Source Project: jdk8u60   Author: chenghanpeng   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison isMoreSpecific(final MethodType t1, final MethodType t2, final boolean varArgs, final Class<?>[] argTypes,
        final LinkerServices ls) {
    final int pc1 = t1.parameterCount();
    final int pc2 = t2.parameterCount();
    assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
    assert (argTypes == null) == (ls == null);
    final int maxPc = Math.max(Math.max(pc1, pc2), argTypes == null ? 0 : argTypes.length);
    boolean t1MoreSpecific = false;
    boolean t2MoreSpecific = false;
    // NOTE: Starting from 1 as overloaded method resolution doesn't depend on 0th element, which is the type of
    // 'this'. We're only dealing with instance methods here, not static methods. Actually, static methods will have
    // a fake 'this' of type StaticClass.
    for(int i = 1; i < maxPc; ++i) {
        final Class<?> c1 = getParameterClass(t1, pc1, i, varArgs);
        final Class<?> c2 = getParameterClass(t2, pc2, i, varArgs);
        if(c1 != c2) {
            final Comparison cmp = compare(c1, c2, argTypes, i, ls);
            if(cmp == Comparison.TYPE_1_BETTER && !t1MoreSpecific) {
                t1MoreSpecific = true;
                if(t2MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
            if(cmp == Comparison.TYPE_2_BETTER && !t2MoreSpecific) {
                t2MoreSpecific = true;
                if(t1MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
        }
    }
    if(t1MoreSpecific) {
        return Comparison.TYPE_1_BETTER;
    } else if(t2MoreSpecific) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #15
Source Project: jdk8u60   Author: chenghanpeng   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(final Class<?> c1, final Class<?> c2, final Class<?>[] argTypes, final int i, final LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #16
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NashornBeansLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if (sourceType == ConsString.class) {
        if (String.class == targetType1 || CharSequence.class == targetType1) {
            return Comparison.TYPE_1_BETTER;
        }

        if (String.class == targetType2 || CharSequence.class == targetType2) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return linkerServices.compareConversion(sourceType, targetType1, targetType2);
}
 
Example #17
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison isMoreSpecific(final MethodType t1, final MethodType t2, final boolean varArgs, final Class<?>[] argTypes,
        final LinkerServices ls) {
    final int pc1 = t1.parameterCount();
    final int pc2 = t2.parameterCount();
    assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
    assert (argTypes == null) == (ls == null);
    final int maxPc = Math.max(Math.max(pc1, pc2), argTypes == null ? 0 : argTypes.length);
    boolean t1MoreSpecific = false;
    boolean t2MoreSpecific = false;
    // NOTE: Starting from 1 as overloaded method resolution doesn't depend on 0th element, which is the type of
    // 'this'. We're only dealing with instance methods here, not static methods. Actually, static methods will have
    // a fake 'this' of type StaticClass.
    for(int i = 1; i < maxPc; ++i) {
        final Class<?> c1 = getParameterClass(t1, pc1, i, varArgs);
        final Class<?> c2 = getParameterClass(t2, pc2, i, varArgs);
        if(c1 != c2) {
            final Comparison cmp = compare(c1, c2, argTypes, i, ls);
            if(cmp == Comparison.TYPE_1_BETTER && !t1MoreSpecific) {
                t1MoreSpecific = true;
                if(t2MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
            if(cmp == Comparison.TYPE_2_BETTER && !t2MoreSpecific) {
                t2MoreSpecific = true;
                if(t1MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
        }
    }
    if(t1MoreSpecific) {
        return Comparison.TYPE_1_BETTER;
    } else if(t2MoreSpecific) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #18
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(final Class<?> c1, final Class<?> c2, final Class<?>[] argTypes, final int i, final LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #19
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: NashornBeansLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if (sourceType == ConsString.class) {
        if (String.class == targetType1 || CharSequence.class == targetType1) {
            return Comparison.TYPE_1_BETTER;
        }

        if (String.class == targetType2 || CharSequence.class == targetType2) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return linkerServices.compareConversion(sourceType, targetType1, targetType2);
}
 
Example #20
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison isMoreSpecific(final MethodType t1, final MethodType t2, final boolean varArgs, final Class<?>[] argTypes,
        final LinkerServices ls) {
    final int pc1 = t1.parameterCount();
    final int pc2 = t2.parameterCount();
    assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
    assert (argTypes == null) == (ls == null);
    final int maxPc = Math.max(Math.max(pc1, pc2), argTypes == null ? 0 : argTypes.length);
    boolean t1MoreSpecific = false;
    boolean t2MoreSpecific = false;
    // NOTE: Starting from 1 as overloaded method resolution doesn't depend on 0th element, which is the type of
    // 'this'. We're only dealing with instance methods here, not static methods. Actually, static methods will have
    // a fake 'this' of type StaticClass.
    for(int i = 1; i < maxPc; ++i) {
        final Class<?> c1 = getParameterClass(t1, pc1, i, varArgs);
        final Class<?> c2 = getParameterClass(t2, pc2, i, varArgs);
        if(c1 != c2) {
            final Comparison cmp = compare(c1, c2, argTypes, i, ls);
            if(cmp == Comparison.TYPE_1_BETTER && !t1MoreSpecific) {
                t1MoreSpecific = true;
                if(t2MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
            if(cmp == Comparison.TYPE_2_BETTER && !t2MoreSpecific) {
                t2MoreSpecific = true;
                if(t1MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
        }
    }
    if(t1MoreSpecific) {
        return Comparison.TYPE_1_BETTER;
    } else if(t2MoreSpecific) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #21
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(final Class<?> c1, final Class<?> c2, final Class<?>[] argTypes, final int i, final LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #22
Source Project: hottub   Author: dsrg-uoft   File: NashornBeansLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if (sourceType == ConsString.class) {
        if (String.class == targetType1 || CharSequence.class == targetType1) {
            return Comparison.TYPE_1_BETTER;
        }

        if (String.class == targetType2 || CharSequence.class == targetType2) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return linkerServices.compareConversion(sourceType, targetType1, targetType2);
}
 
Example #23
Source Project: hottub   Author: dsrg-uoft   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison isMoreSpecific(final MethodType t1, final MethodType t2, final boolean varArgs, final Class<?>[] argTypes,
        final LinkerServices ls) {
    final int pc1 = t1.parameterCount();
    final int pc2 = t2.parameterCount();
    assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
    assert (argTypes == null) == (ls == null);
    final int maxPc = Math.max(Math.max(pc1, pc2), argTypes == null ? 0 : argTypes.length);
    boolean t1MoreSpecific = false;
    boolean t2MoreSpecific = false;
    // NOTE: Starting from 1 as overloaded method resolution doesn't depend on 0th element, which is the type of
    // 'this'. We're only dealing with instance methods here, not static methods. Actually, static methods will have
    // a fake 'this' of type StaticClass.
    for(int i = 1; i < maxPc; ++i) {
        final Class<?> c1 = getParameterClass(t1, pc1, i, varArgs);
        final Class<?> c2 = getParameterClass(t2, pc2, i, varArgs);
        if(c1 != c2) {
            final Comparison cmp = compare(c1, c2, argTypes, i, ls);
            if(cmp == Comparison.TYPE_1_BETTER && !t1MoreSpecific) {
                t1MoreSpecific = true;
                if(t2MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
            if(cmp == Comparison.TYPE_2_BETTER && !t2MoreSpecific) {
                t2MoreSpecific = true;
                if(t1MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
        }
    }
    if(t1MoreSpecific) {
        return Comparison.TYPE_1_BETTER;
    } else if(t2MoreSpecific) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #24
Source Project: hottub   Author: dsrg-uoft   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(final Class<?> c1, final Class<?> c2, final Class<?>[] argTypes, final int i, final LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #25
Source Project: openjdk-8-source   Author: keerath   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison isMoreSpecific(MethodType t1, MethodType t2, boolean varArgs, Class<?>[] argTypes,
        LinkerServices ls) {
    final int pc1 = t1.parameterCount();
    final int pc2 = t2.parameterCount();
    assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
    assert (argTypes == null) == (ls == null);
    final int maxPc = Math.max(Math.max(pc1, pc2), argTypes == null ? 0 : argTypes.length);
    boolean t1MoreSpecific = false;
    boolean t2MoreSpecific = false;
    // NOTE: Starting from 1 as overloaded method resolution doesn't depend on 0th element, which is the type of
    // 'this'. We're only dealing with instance methods here, not static methods. Actually, static methods will have
    // a fake 'this' of type StaticClass.
    for(int i = 1; i < maxPc; ++i) {
        final Class<?> c1 = getParameterClass(t1, pc1, i, varArgs);
        final Class<?> c2 = getParameterClass(t2, pc2, i, varArgs);
        if(c1 != c2) {
            final Comparison cmp = compare(c1, c2, argTypes, i, ls);
            if(cmp == Comparison.TYPE_1_BETTER && !t1MoreSpecific) {
                t1MoreSpecific = true;
                if(t2MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
            if(cmp == Comparison.TYPE_2_BETTER && !t2MoreSpecific) {
                t2MoreSpecific = true;
                if(t1MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
        }
    }
    if(t1MoreSpecific) {
        return Comparison.TYPE_1_BETTER;
    } else if(t2MoreSpecific) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #26
Source Project: openjdk-8-source   Author: keerath   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(Class<?> c1, Class<?> c2, Class<?>[] argTypes, int i, LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #27
Source Project: openjdk-8   Author: bpupadhyaya   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison isMoreSpecific(MethodType t1, MethodType t2, boolean varArgs, Class<?>[] argTypes,
        LinkerServices ls) {
    final int pc1 = t1.parameterCount();
    final int pc2 = t2.parameterCount();
    assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
    assert (argTypes == null) == (ls == null);
    final int maxPc = Math.max(Math.max(pc1, pc2), argTypes == null ? 0 : argTypes.length);
    boolean t1MoreSpecific = false;
    boolean t2MoreSpecific = false;
    // NOTE: Starting from 1 as overloaded method resolution doesn't depend on 0th element, which is the type of
    // 'this'. We're only dealing with instance methods here, not static methods. Actually, static methods will have
    // a fake 'this' of type StaticClass.
    for(int i = 1; i < maxPc; ++i) {
        final Class<?> c1 = getParameterClass(t1, pc1, i, varArgs);
        final Class<?> c2 = getParameterClass(t2, pc2, i, varArgs);
        if(c1 != c2) {
            final Comparison cmp = compare(c1, c2, argTypes, i, ls);
            if(cmp == Comparison.TYPE_1_BETTER && !t1MoreSpecific) {
                t1MoreSpecific = true;
                if(t2MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
            if(cmp == Comparison.TYPE_2_BETTER && !t2MoreSpecific) {
                t2MoreSpecific = true;
                if(t1MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
        }
    }
    if(t1MoreSpecific) {
        return Comparison.TYPE_1_BETTER;
    } else if(t2MoreSpecific) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #28
Source Project: openjdk-8   Author: bpupadhyaya   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison compare(Class<?> c1, Class<?> c2, Class<?>[] argTypes, int i, LinkerServices cmp) {
    if(cmp != null) {
        final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
        if(c != Comparison.INDETERMINATE) {
            return c;
        }
    }
    if(TypeUtilities.isSubtype(c1, c2)) {
        return Comparison.TYPE_1_BETTER;
    } if(TypeUtilities.isSubtype(c2, c1)) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}
 
Example #29
Source Project: jdk8u_nashorn   Author: JetBrains   File: NashornBeansLinker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if (sourceType == ConsString.class) {
        if (String.class == targetType1 || CharSequence.class == targetType1) {
            return Comparison.TYPE_1_BETTER;
        }

        if (String.class == targetType2 || CharSequence.class == targetType2) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return linkerServices.compareConversion(sourceType, targetType1, targetType2);
}
 
Example #30
Source Project: jdk8u_nashorn   Author: JetBrains   File: MaximallySpecific.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Comparison isMoreSpecific(final MethodType t1, final MethodType t2, final boolean varArgs, final Class<?>[] argTypes,
        final LinkerServices ls) {
    final int pc1 = t1.parameterCount();
    final int pc2 = t2.parameterCount();
    assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
    assert (argTypes == null) == (ls == null);
    final int maxPc = Math.max(Math.max(pc1, pc2), argTypes == null ? 0 : argTypes.length);
    boolean t1MoreSpecific = false;
    boolean t2MoreSpecific = false;
    // NOTE: Starting from 1 as overloaded method resolution doesn't depend on 0th element, which is the type of
    // 'this'. We're only dealing with instance methods here, not static methods. Actually, static methods will have
    // a fake 'this' of type StaticClass.
    for(int i = 1; i < maxPc; ++i) {
        final Class<?> c1 = getParameterClass(t1, pc1, i, varArgs);
        final Class<?> c2 = getParameterClass(t2, pc2, i, varArgs);
        if(c1 != c2) {
            final Comparison cmp = compare(c1, c2, argTypes, i, ls);
            if(cmp == Comparison.TYPE_1_BETTER && !t1MoreSpecific) {
                t1MoreSpecific = true;
                if(t2MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
            if(cmp == Comparison.TYPE_2_BETTER && !t2MoreSpecific) {
                t2MoreSpecific = true;
                if(t1MoreSpecific) {
                    return Comparison.INDETERMINATE;
                }
            }
        }
    }
    if(t1MoreSpecific) {
        return Comparison.TYPE_1_BETTER;
    } else if(t2MoreSpecific) {
        return Comparison.TYPE_2_BETTER;
    }
    return Comparison.INDETERMINATE;
}