Java源码示例:jdk.internal.dynalink.linker.GuardedTypeConversion
示例1
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final MethodType type = MethodType.methodType(targetType, sourceType);
final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
MethodHandle last = identity;
boolean cacheable = true;
for(int i = factories.length; i-- > 0;) {
final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
if(next != null) {
cacheable = cacheable && next.isCacheable();
final GuardedInvocation conversionInvocation = next.getConversionInvocation();
conversionInvocation.assertType(type);
last = conversionInvocation.compose(last);
}
}
if(last == identity) {
return IDENTITY_CONVERSION;
}
if(cacheable) {
return last;
}
throw new NotCacheableConverter(last);
}
示例2
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final MethodType type = MethodType.methodType(targetType, sourceType);
final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
MethodHandle last = identity;
boolean cacheable = true;
for(int i = factories.length; i-- > 0;) {
final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
if(next != null) {
cacheable = cacheable && next.isCacheable();
final GuardedInvocation conversionInvocation = next.getConversionInvocation();
conversionInvocation.assertType(type);
last = conversionInvocation.compose(last);
}
}
if(last == identity) {
return IDENTITY_CONVERSION;
}
if(cacheable) {
return last;
}
throw new NotCacheableConverter(last);
}
示例3
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final MethodType type = MethodType.methodType(targetType, sourceType);
final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
MethodHandle last = identity;
boolean cacheable = true;
for(int i = factories.length; i-- > 0;) {
final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
if(next != null) {
cacheable = cacheable && next.isCacheable();
final GuardedInvocation conversionInvocation = next.getConversionInvocation();
conversionInvocation.assertType(type);
last = conversionInvocation.compose(last);
}
}
if(last == identity) {
return IDENTITY_CONVERSION;
}
if(cacheable) {
return last;
}
throw new NotCacheableConverter(last);
}
示例4
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final MethodType type = MethodType.methodType(targetType, sourceType);
final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
MethodHandle last = identity;
boolean cacheable = true;
for(int i = factories.length; i-- > 0;) {
final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
if(next != null) {
cacheable = cacheable && next.isCacheable();
final GuardedInvocation conversionInvocation = next.getConversionInvocation();
conversionInvocation.assertType(type);
last = conversionInvocation.compose(last);
}
}
if(last == identity) {
return IDENTITY_CONVERSION;
}
if(cacheable) {
return last;
}
throw new NotCacheableConverter(last);
}
示例5
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final MethodType type = MethodType.methodType(targetType, sourceType);
final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
MethodHandle last = identity;
boolean cacheable = true;
for(int i = factories.length; i-- > 0;) {
final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
if(next != null) {
cacheable = cacheable && next.isCacheable();
final GuardedInvocation conversionInvocation = next.getConversionInvocation();
conversionInvocation.assertType(type);
last = conversionInvocation.compose(last);
}
}
if(last == identity) {
return IDENTITY_CONVERSION;
}
if(cacheable) {
return last;
}
throw new NotCacheableConverter(last);
}
示例6
MethodHandle createConverter(Class<?> sourceType, Class<?> targetType) throws Exception {
final MethodType type = MethodType.methodType(targetType, sourceType);
final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
MethodHandle last = identity;
boolean cacheable = true;
for(int i = factories.length; i-- > 0;) {
final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
if(next != null) {
cacheable = cacheable && next.isCacheable();
final GuardedInvocation conversionInvocation = next.getConversionInvocation();
conversionInvocation.assertType(type);
last = conversionInvocation.compose(last);
}
}
if(last == identity) {
return IDENTITY_CONVERSION;
}
if(cacheable) {
return last;
}
throw new NotCacheableConverter(last);
}
示例7
MethodHandle createConverter(Class<?> sourceType, Class<?> targetType) throws Exception {
final MethodType type = MethodType.methodType(targetType, sourceType);
final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
MethodHandle last = identity;
boolean cacheable = true;
for(int i = factories.length; i-- > 0;) {
final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
if(next != null) {
cacheable = cacheable && next.isCacheable();
final GuardedInvocation conversionInvocation = next.getConversionInvocation();
conversionInvocation.assertType(type);
last = conversionInvocation.compose(last);
}
}
if(last == identity) {
return IDENTITY_CONVERSION;
}
if(cacheable) {
return last;
}
throw new NotCacheableConverter(last);
}
示例8
MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final MethodType type = MethodType.methodType(targetType, sourceType);
final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
MethodHandle last = identity;
boolean cacheable = true;
for(int i = factories.length; i-- > 0;) {
final GuardedTypeConversion next = factories[i].convertToType(sourceType, targetType);
if(next != null) {
cacheable = cacheable && next.isCacheable();
final GuardedInvocation conversionInvocation = next.getConversionInvocation();
conversionInvocation.assertType(type);
last = conversionInvocation.compose(last);
}
}
if(last == identity) {
return IDENTITY_CONVERSION;
}
if(cacheable) {
return last;
}
throw new NotCacheableConverter(last);
}
示例9
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
gi = getSamTypeConverter(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), false);
}
return null;
}
示例10
/**
* This implementation of type converter factory will pretty much allow implicit conversions of anything to anything
* else that's allowed among JavaScript primitive types (string to number, boolean to string, etc.)
* @param sourceType the type to convert from
* @param targetType the type to convert to
* @return a conditional converter from source to target type
*/
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) {
final MethodHandle mh = JavaArgumentConverters.getConverter(targetType);
if (mh == null) {
if(targetType == Object.class && sourceType == void.class) {
return VOID_TO_OBJECT;
}
return null;
}
return new GuardedTypeConversion(new GuardedInvocation(mh, canLinkTypeStatic(sourceType) ? null : GUARD_PRIMITIVE).asType(mh.type().changeParameterType(0, sourceType)), true);
}
示例11
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
gi = getSamTypeConverter(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), false);
}
return null;
}
示例12
/**
* This implementation of type converter factory will pretty much allow implicit conversions of anything to anything
* else that's allowed among JavaScript primitive types (string to number, boolean to string, etc.)
* @param sourceType the type to convert from
* @param targetType the type to convert to
* @return a conditional converter from source to target type
*/
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) {
final MethodHandle mh = JavaArgumentConverters.getConverter(targetType);
if (mh == null) {
if(targetType == Object.class && sourceType == void.class) {
return VOID_TO_OBJECT;
}
return null;
}
return new GuardedTypeConversion(new GuardedInvocation(mh, canLinkTypeStatic(sourceType) ? null : GUARD_PRIMITIVE).asType(mh.type().changeParameterType(0, sourceType)), true);
}
示例13
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
gi = getSamTypeConverter(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), false);
}
return null;
}
示例14
/**
* This implementation of type converter factory will pretty much allow implicit conversions of anything to anything
* else that's allowed among JavaScript primitive types (string to number, boolean to string, etc.)
* @param sourceType the type to convert from
* @param targetType the type to convert to
* @return a conditional converter from source to target type
*/
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) {
final MethodHandle mh = JavaArgumentConverters.getConverter(targetType);
if (mh == null) {
if(targetType == Object.class && sourceType == void.class) {
return VOID_TO_OBJECT;
}
return null;
}
return new GuardedTypeConversion(new GuardedInvocation(mh, canLinkTypeStatic(sourceType) ? null : GUARD_PRIMITIVE).asType(mh.type().changeParameterType(0, sourceType)), true);
}
示例15
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
gi = getSamTypeConverter(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), false);
}
return null;
}
示例16
/**
* This implementation of type converter factory will pretty much allow implicit conversions of anything to anything
* else that's allowed among JavaScript primitive types (string to number, boolean to string, etc.)
* @param sourceType the type to convert from
* @param targetType the type to convert to
* @return a conditional converter from source to target type
*/
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) {
final MethodHandle mh = JavaArgumentConverters.getConverter(targetType);
if (mh == null) {
if(targetType == Object.class && sourceType == void.class) {
return VOID_TO_OBJECT;
}
return null;
}
return new GuardedTypeConversion(new GuardedInvocation(mh, canLinkTypeStatic(sourceType) ? null : GUARD_PRIMITIVE).asType(mh.type().changeParameterType(0, sourceType)), true);
}
示例17
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
gi = getSamTypeConverter(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), false);
}
return null;
}
示例18
/**
* This implementation of type converter factory will pretty much allow implicit conversions of anything to anything
* else that's allowed among JavaScript primitive types (string to number, boolean to string, etc.)
* @param sourceType the type to convert from
* @param targetType the type to convert to
* @return a conditional converter from source to target type
*/
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) {
final MethodHandle mh = JavaArgumentConverters.getConverter(targetType);
if (mh == null) {
if(targetType == Object.class && sourceType == void.class) {
return VOID_TO_OBJECT;
}
return null;
}
return new GuardedTypeConversion(new GuardedInvocation(mh, canLinkTypeStatic(sourceType) ? null : GUARD_PRIMITIVE).asType(mh.type().changeParameterType(0, sourceType)), true);
}
示例19
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
gi = getSamTypeConverter(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), false);
}
return null;
}
示例20
/**
* This implementation of type converter factory will pretty much allow implicit conversions of anything to anything
* else that's allowed among JavaScript primitive types (string to number, boolean to string, etc.)
* @param sourceType the type to convert from
* @param targetType the type to convert to
* @return a conditional converter from source to target type
*/
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) {
final MethodHandle mh = JavaArgumentConverters.getConverter(targetType);
if (mh == null) {
return null;
}
return new GuardedTypeConversion(new GuardedInvocation(mh, canLinkTypeStatic(sourceType) ? null : GUARD_PRIMITIVE).asType(mh.type().changeParameterType(0, sourceType)), true);
}
示例21
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final boolean sourceIsAlwaysJSObject = JSObject.class.isAssignableFrom(sourceType);
if(!sourceIsAlwaysJSObject && !sourceType.isAssignableFrom(JSObject.class)) {
return null;
}
final MethodHandle converter = CONVERTERS.get(targetType);
if(converter == null) {
return null;
}
return new GuardedTypeConversion(new GuardedInvocation(converter, sourceIsAlwaysJSObject ? null : IS_JSOBJECT_GUARD).asType(MethodType.methodType(targetType, sourceType)), true);
}
示例22
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
gi = getSamTypeConverter(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), false);
}
return null;
}
示例23
/**
* This implementation of type converter factory will pretty much allow implicit conversions of anything to anything
* else that's allowed among JavaScript primitive types (string to number, boolean to string, etc.)
* @param sourceType the type to convert from
* @param targetType the type to convert to
* @return a conditional converter from source to target type
*/
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) {
final MethodHandle mh = JavaArgumentConverters.getConverter(targetType);
if (mh == null) {
return null;
}
return new GuardedTypeConversion(new GuardedInvocation(mh, canLinkTypeStatic(sourceType) ? null : GUARD_PRIMITIVE).asType(mh.type().changeParameterType(0, sourceType)), true);
}
示例24
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final boolean sourceIsAlwaysJSObject = JSObject.class.isAssignableFrom(sourceType);
if(!sourceIsAlwaysJSObject && !sourceType.isAssignableFrom(JSObject.class)) {
return null;
}
final MethodHandle converter = CONVERTERS.get(targetType);
if(converter == null) {
return null;
}
return new GuardedTypeConversion(new GuardedInvocation(converter, sourceIsAlwaysJSObject ? null : IS_JSOBJECT_GUARD).asType(MethodType.methodType(targetType, sourceType)), true);
}
示例25
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
gi = getSamTypeConverter(sourceType, targetType);
if(gi != null) {
return new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), false);
}
return null;
}
示例26
/**
* This implementation of type converter factory will pretty much allow implicit conversions of anything to anything
* else that's allowed among JavaScript primitive types (string to number, boolean to string, etc.)
* @param sourceType the type to convert from
* @param targetType the type to convert to
* @return a conditional converter from source to target type
*/
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) {
final MethodHandle mh = JavaArgumentConverters.getConverter(targetType);
if (mh == null) {
if(targetType == Object.class && sourceType == void.class) {
return VOID_TO_OBJECT;
}
return null;
}
return new GuardedTypeConversion(new GuardedInvocation(mh, canLinkTypeStatic(sourceType) ? null : GUARD_PRIMITIVE).asType(mh.type().changeParameterType(0, sourceType)), true);
}
示例27
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
return gi == null ? null : new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
示例28
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
return gi == null ? null : new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
示例29
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
return gi == null ? null : new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}
示例30
@Override
public GuardedTypeConversion convertToType(final Class<?> sourceType, final Class<?> targetType) throws Exception {
final GuardedInvocation gi = convertToTypeNoCast(sourceType, targetType);
return gi == null ? null : new GuardedTypeConversion(gi.asType(MH.type(targetType, sourceType)), true);
}