Java Code Examples for jdk.internal.dynalink.linker.LinkerServices#getTypeConverter()
The following examples show how to use
jdk.internal.dynalink.linker.LinkerServices#getTypeConverter() .
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 File: ScriptUtils.java License: GNU General Public License v2.0 | 5 votes |
/** * Convert the given object to the given type. * * @param obj object to be converted * @param type destination type to convert to. type is either a Class * or nashorn representation of a Java type returned by Java.type() call in script. * @return converted object */ public static Object convert(final Object obj, final Object type) { if (obj == null) { return null; } final Class<?> clazz; if (type instanceof Class) { clazz = (Class<?>)type; } else if (type instanceof StaticClass) { clazz = ((StaticClass)type).getRepresentedClass(); } else { throw new IllegalArgumentException("type expected"); } final LinkerServices linker = Bootstrap.getLinkerServices(); final Object objToConvert = unwrap(obj); final MethodHandle converter = linker.getTypeConverter(objToConvert.getClass(), clazz); if (converter == null) { // no supported conversion! throw new UnsupportedOperationException("conversion not supported"); } try { return converter.invoke(objToConvert); } catch (final RuntimeException | Error e) { throw e; } catch (final Throwable t) { throw new RuntimeException(t); } }
Example 2
Source Project: TencentKona-8 File: BeanLinker.java License: GNU General Public License v2.0 | 5 votes |
private static MethodHandle convertArgToInt(final MethodHandle mh, final LinkerServices ls, final CallSiteDescriptor desc) { final Class<?> sourceType = desc.getMethodType().parameterType(1); if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) { return mh; } else if(ls.canConvert(sourceType, Number.class)) { final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class); return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType( mh.type().parameterType(1)))); } return mh; }
Example 3
Source Project: jdk8u60 File: ScriptUtils.java License: GNU General Public License v2.0 | 5 votes |
/** * Convert the given object to the given type. * * @param obj object to be converted * @param type destination type to convert to * @return converted object */ public static Object convert(final Object obj, final Object type) { if (obj == null) { return null; } final Class<?> clazz; if (type instanceof Class) { clazz = (Class<?>)type; } else if (type instanceof StaticClass) { clazz = ((StaticClass)type).getRepresentedClass(); } else { throw new IllegalArgumentException("type expected"); } final LinkerServices linker = Bootstrap.getLinkerServices(); final Object objToConvert = unwrap(obj); final MethodHandle converter = linker.getTypeConverter(objToConvert.getClass(), clazz); if (converter == null) { // no supported conversion! throw new UnsupportedOperationException("conversion not supported"); } try { return converter.invoke(objToConvert); } catch (final RuntimeException | Error e) { throw e; } catch (final Throwable t) { throw new RuntimeException(t); } }
Example 4
Source Project: jdk8u60 File: BeanLinker.java License: GNU General Public License v2.0 | 5 votes |
private static MethodHandle convertArgToInt(final MethodHandle mh, final LinkerServices ls, final CallSiteDescriptor desc) { final Class<?> sourceType = desc.getMethodType().parameterType(1); if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) { return mh; } else if(ls.canConvert(sourceType, Number.class)) { final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class); return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType( mh.type().parameterType(1)))); } return mh; }
Example 5
Source Project: openjdk-jdk8u File: ScriptUtils.java License: GNU General Public License v2.0 | 5 votes |
/** * Convert the given object to the given type. * * @param obj object to be converted * @param type destination type to convert to. type is either a Class * or nashorn representation of a Java type returned by Java.type() call in script. * @return converted object */ public static Object convert(final Object obj, final Object type) { if (obj == null) { return null; } final Class<?> clazz; if (type instanceof Class) { clazz = (Class<?>)type; } else if (type instanceof StaticClass) { clazz = ((StaticClass)type).getRepresentedClass(); } else { throw new IllegalArgumentException("type expected"); } final LinkerServices linker = Bootstrap.getLinkerServices(); final Object objToConvert = unwrap(obj); final MethodHandle converter = linker.getTypeConverter(objToConvert.getClass(), clazz); if (converter == null) { // no supported conversion! throw new UnsupportedOperationException("conversion not supported"); } try { return converter.invoke(objToConvert); } catch (final RuntimeException | Error e) { throw e; } catch (final Throwable t) { throw new RuntimeException(t); } }
Example 6
Source Project: openjdk-jdk8u File: BeanLinker.java License: GNU General Public License v2.0 | 5 votes |
private static MethodHandle convertArgToInt(final MethodHandle mh, final LinkerServices ls, final CallSiteDescriptor desc) { final Class<?> sourceType = desc.getMethodType().parameterType(1); if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) { return mh; } else if(ls.canConvert(sourceType, Number.class)) { final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class); return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType( mh.type().parameterType(1)))); } return mh; }
Example 7
Source Project: openjdk-jdk8u-backup File: ScriptUtils.java License: GNU General Public License v2.0 | 5 votes |
/** * Convert the given object to the given type. * * @param obj object to be converted * @param type destination type to convert to. type is either a Class * or nashorn representation of a Java type returned by Java.type() call in script. * @return converted object */ public static Object convert(final Object obj, final Object type) { if (obj == null) { return null; } final Class<?> clazz; if (type instanceof Class) { clazz = (Class<?>)type; } else if (type instanceof StaticClass) { clazz = ((StaticClass)type).getRepresentedClass(); } else { throw new IllegalArgumentException("type expected"); } final LinkerServices linker = Bootstrap.getLinkerServices(); final Object objToConvert = unwrap(obj); final MethodHandle converter = linker.getTypeConverter(objToConvert.getClass(), clazz); if (converter == null) { // no supported conversion! throw new UnsupportedOperationException("conversion not supported"); } try { return converter.invoke(objToConvert); } catch (final RuntimeException | Error e) { throw e; } catch (final Throwable t) { throw new RuntimeException(t); } }
Example 8
Source Project: openjdk-jdk8u-backup File: BeanLinker.java License: GNU General Public License v2.0 | 5 votes |
private static MethodHandle convertArgToInt(final MethodHandle mh, final LinkerServices ls, final CallSiteDescriptor desc) { final Class<?> sourceType = desc.getMethodType().parameterType(1); if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) { return mh; } else if(ls.canConvert(sourceType, Number.class)) { final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class); return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType( mh.type().parameterType(1)))); } return mh; }
Example 9
Source Project: hottub File: ScriptUtils.java License: GNU General Public License v2.0 | 5 votes |
/** * Convert the given object to the given type. * * @param obj object to be converted * @param type destination type to convert to. type is either a Class * or nashorn representation of a Java type returned by Java.type() call in script. * @return converted object */ public static Object convert(final Object obj, final Object type) { if (obj == null) { return null; } final Class<?> clazz; if (type instanceof Class) { clazz = (Class<?>)type; } else if (type instanceof StaticClass) { clazz = ((StaticClass)type).getRepresentedClass(); } else { throw new IllegalArgumentException("type expected"); } final LinkerServices linker = Bootstrap.getLinkerServices(); final Object objToConvert = unwrap(obj); final MethodHandle converter = linker.getTypeConverter(objToConvert.getClass(), clazz); if (converter == null) { // no supported conversion! throw new UnsupportedOperationException("conversion not supported"); } try { return converter.invoke(objToConvert); } catch (final RuntimeException | Error e) { throw e; } catch (final Throwable t) { throw new RuntimeException(t); } }
Example 10
Source Project: hottub File: BeanLinker.java License: GNU General Public License v2.0 | 5 votes |
private static MethodHandle convertArgToInt(final MethodHandle mh, final LinkerServices ls, final CallSiteDescriptor desc) { final Class<?> sourceType = desc.getMethodType().parameterType(1); if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) { return mh; } else if(ls.canConvert(sourceType, Number.class)) { final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class); return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType( mh.type().parameterType(1)))); } return mh; }
Example 11
Source Project: openjdk-8-source File: ScriptUtils.java License: GNU General Public License v2.0 | 5 votes |
/** * Convert the given object to the given type. * * @param obj object to be converted * @param type destination type to convert to * @return converted object */ public static Object convert(final Object obj, final Object type) { if (obj == null) { return null; } final Class<?> clazz; if (type instanceof Class) { clazz = (Class<?>)type; } else if (type instanceof StaticClass) { clazz = ((StaticClass)type).getRepresentedClass(); } else { throw new IllegalArgumentException("type expected"); } final LinkerServices linker = Bootstrap.getLinkerServices(); final MethodHandle converter = linker.getTypeConverter(obj.getClass(), clazz); if (converter == null) { // no supported conversion! throw new UnsupportedOperationException("conversion not supported"); } try { return converter.invoke(obj); } catch (final RuntimeException | Error e) { throw e; } catch (final Throwable t) { throw new RuntimeException(t); } }
Example 12
Source Project: openjdk-8-source File: BeanLinker.java License: GNU General Public License v2.0 | 5 votes |
private static MethodHandle convertArgToInt(MethodHandle mh, LinkerServices ls, CallSiteDescriptor desc) { final Class<?> sourceType = desc.getMethodType().parameterType(1); if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) { return mh; } else if(ls.canConvert(sourceType, Number.class)) { final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class); return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType( mh.type().parameterType(1)))); } return mh; }
Example 13
Source Project: openjdk-8 File: ScriptUtils.java License: GNU General Public License v2.0 | 5 votes |
/** * Convert the given object to the given type. * * @param obj object to be converted * @param type destination type to convert to * @return converted object */ public static Object convert(final Object obj, final Object type) { if (obj == null) { return null; } final Class<?> clazz; if (type instanceof Class) { clazz = (Class<?>)type; } else if (type instanceof StaticClass) { clazz = ((StaticClass)type).getRepresentedClass(); } else { throw new IllegalArgumentException("type expected"); } final LinkerServices linker = Bootstrap.getLinkerServices(); final MethodHandle converter = linker.getTypeConverter(obj.getClass(), clazz); if (converter == null) { // no supported conversion! throw new UnsupportedOperationException("conversion not supported"); } try { return converter.invoke(obj); } catch (final RuntimeException | Error e) { throw e; } catch (final Throwable t) { throw new RuntimeException(t); } }
Example 14
Source Project: openjdk-8 File: BeanLinker.java License: GNU General Public License v2.0 | 5 votes |
private static MethodHandle convertArgToInt(MethodHandle mh, LinkerServices ls, CallSiteDescriptor desc) { final Class<?> sourceType = desc.getMethodType().parameterType(1); if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) { return mh; } else if(ls.canConvert(sourceType, Number.class)) { final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class); return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType( mh.type().parameterType(1)))); } return mh; }
Example 15
Source Project: jdk8u_nashorn File: ScriptUtils.java License: GNU General Public License v2.0 | 5 votes |
/** * Convert the given object to the given type. * * @param obj object to be converted * @param type destination type to convert to. type is either a Class * or nashorn representation of a Java type returned by Java.type() call in script. * @return converted object */ public static Object convert(final Object obj, final Object type) { if (obj == null) { return null; } final Class<?> clazz; if (type instanceof Class) { clazz = (Class<?>)type; } else if (type instanceof StaticClass) { clazz = ((StaticClass)type).getRepresentedClass(); } else { throw new IllegalArgumentException("type expected"); } final LinkerServices linker = Bootstrap.getLinkerServices(); final Object objToConvert = unwrap(obj); final MethodHandle converter = linker.getTypeConverter(objToConvert.getClass(), clazz); if (converter == null) { // no supported conversion! throw new UnsupportedOperationException("conversion not supported"); } try { return converter.invoke(objToConvert); } catch (final RuntimeException | Error e) { throw e; } catch (final Throwable t) { throw new RuntimeException(t); } }
Example 16
Source Project: jdk8u_nashorn File: BeanLinker.java License: GNU General Public License v2.0 | 5 votes |
private static MethodHandle convertArgToInt(final MethodHandle mh, final LinkerServices ls, final CallSiteDescriptor desc) { final Class<?> sourceType = desc.getMethodType().parameterType(1); if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) { return mh; } else if(ls.canConvert(sourceType, Number.class)) { final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class); return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType( mh.type().parameterType(1)))); } return mh; }
Example 17
Source Project: nashorn File: BeanLinker.java License: GNU General Public License v2.0 | 5 votes |
private static MethodHandle convertArgToInt(MethodHandle mh, LinkerServices ls, CallSiteDescriptor desc) { final Class<?> sourceType = desc.getMethodType().parameterType(1); if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) { return mh; } else if(ls.canConvert(sourceType, Number.class)) { final MethodHandle converter = ls.getTypeConverter(sourceType, Number.class); return MethodHandles.filterArguments(mh, 1, converter.asType(converter.type().changeReturnType( mh.type().parameterType(1)))); } return mh; }