Java Code Examples for java.lang.invoke.MethodType#generic()

The following examples show how to use java.lang.invoke.MethodType#generic() . 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: ScriptFunctionData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static MethodType makeGenericType(final MethodType type) {
    MethodType newType = type.generic();
    if (isVarArg(type)) {
        newType = newType.changeParameterType(type.parameterCount() - 1, Object[].class);
    }
    if (needsCallee(type)) {
        newType = newType.changeParameterType(0, ScriptFunction.class);
    }
    return newType;
}
 
Example 2
Source File: ScriptFunctionData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static MethodType makeGenericType(final MethodType type) {
    MethodType newType = type.generic();
    if (isVarArg(type)) {
        newType = newType.changeParameterType(type.parameterCount() - 1, Object[].class);
    }
    if (needsCallee(type)) {
        newType = newType.changeParameterType(0, ScriptFunction.class);
    }
    return newType;
}
 
Example 3
Source File: ScriptFunctionData.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static MethodType makeGenericType(final MethodType type) {
    MethodType newType = type.generic();
    if (isVarArg(type)) {
        newType = newType.changeParameterType(type.parameterCount() - 1, Object[].class);
    }
    if (needsCallee(type)) {
        newType = newType.changeParameterType(0, ScriptFunction.class);
    }
    return newType;
}
 
Example 4
Source File: ScriptFunctionData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static MethodType makeGenericType(final MethodType type) {
    MethodType newType = type.generic();
    if (isVarArg(type)) {
        newType = newType.changeParameterType(type.parameterCount() - 1, Object[].class);
    }
    if (needsCallee(type)) {
        newType = newType.changeParameterType(0, ScriptFunction.class);
    }
    return newType;
}
 
Example 5
Source File: ScriptFunctionData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static MethodType makeGenericType(final MethodType type) {
    MethodType newType = type.generic();
    if (isVarArg(type)) {
        newType = newType.changeParameterType(type.parameterCount() - 1, Object[].class);
    }
    if (needsCallee(type)) {
        newType = newType.changeParameterType(0, ScriptFunction.class);
    }
    return newType;
}
 
Example 6
Source File: ScriptFunctionData.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static MethodType makeGenericType(final MethodType type) {
    MethodType newType = type.generic();
    if (isVarArg(type)) {
        newType = newType.changeParameterType(type.parameterCount() - 1, Object[].class);
    }
    if (needsCallee(type)) {
        newType = newType.changeParameterType(0, ScriptFunction.class);
    }
    return newType;
}
 
Example 7
Source File: ScriptFunctionData.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static MethodType makeGenericType(final MethodType type) {
    MethodType newType = type.generic();
    if (isVarArg(type)) {
        newType = newType.changeParameterType(type.parameterCount() - 1, Object[].class);
    }
    if (needsCallee(type)) {
        newType = newType.changeParameterType(0, ScriptFunction.class);
    }
    return newType;
}
 
Example 8
Source File: ScriptFunctionData.java    From nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Takes a method handle, and returns a potentially different method handle that can be used in
 * {@code ScriptFunction#invoke(Object, Object...)} or {code ScriptFunction#construct(Object, Object...)}.
 * The returned method handle will be sure to return {@code Object}, and will have all its parameters turned into
 * {@code Object} as well, except for the following ones:
 * <ul>
 *   <li>a last parameter of type {@code Object[]} which is used for vararg functions,</li>
 *   <li>the first argument, which is forced to be {@link ScriptFunction}, in case the function receives itself
 *   (callee) as an argument.</li>
 * </ul>
 *
 * @param mh the original method handle
 *
 * @return the new handle, conforming to the rules above.
 */
protected MethodHandle composeGenericMethod(final MethodHandle mh) {
    final MethodType type = mh.type();
    MethodType newType = type.generic();
    if (isVarArg(mh)) {
        newType = newType.changeParameterType(type.parameterCount() - 1, Object[].class);
    }
    if (needsCallee(mh)) {
        newType = newType.changeParameterType(0, ScriptFunction.class);
    }
    return type.equals(newType) ? mh : mh.asType(newType);
}