当前位置: 首页>>代码示例>>Java>>正文


Java MethodType.parameterCount方法代码示例

本文整理汇总了Java中java.lang.invoke.MethodType.parameterCount方法的典型用法代码示例。如果您正苦于以下问题:Java MethodType.parameterCount方法的具体用法?Java MethodType.parameterCount怎么用?Java MethodType.parameterCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.invoke.MethodType的用法示例。


在下文中一共展示了MethodType.parameterCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: explicitParams

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private MethodType explicitParams(final MethodType callSiteType) {
    if (CompiledFunction.isVarArgsType(callSiteType)) {
        return null;
    }

    final MethodType noCalleeThisType = callSiteType.dropParameterTypes(0, 2); // (callee, this) is always in call site type
    final int callSiteParamCount = noCalleeThisType.parameterCount();

    // Widen parameters of reference types to Object as we currently don't care for specialization among reference
    // types. E.g. call site saying (ScriptFunction, Object, String) should still link to (ScriptFunction, Object, Object)
    final Class<?>[] paramTypes = noCalleeThisType.parameterArray();
    boolean changed = false;
    for (int i = 0; i < paramTypes.length; ++i) {
        final Class<?> paramType = paramTypes[i];
        if (!(paramType.isPrimitive() || paramType == Object.class)) {
            paramTypes[i] = Object.class;
            changed = true;
        }
    }
    final MethodType generalized = changed ? MethodType.methodType(noCalleeThisType.returnType(), paramTypes) : noCalleeThisType;

    if (callSiteParamCount < getArity()) {
        return generalized.appendParameterTypes(Collections.<Class<?>>nCopies(getArity() - callSiteParamCount, Object.class));
    }
    return generalized;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:RecompilableScriptFunctionData.java

示例2: spreadGuardArguments

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private static MethodHandle spreadGuardArguments(final MethodHandle guard, final MethodType descType) {
    final MethodType guardType = guard.type();
    final int guardParamCount = guardType.parameterCount();
    final int descParamCount = descType.parameterCount();
    final int spreadCount = guardParamCount - descParamCount + 1;
    if (spreadCount <= 0) {
        // Guard doesn't dip into the varargs
        return guard;
    }

    final MethodHandle arrayConvertingGuard;
    // If the last parameter type of the guard is an array, then it is already itself a guard for a vararg apply
    // invocation. We must filter the last argument with toApplyArgs otherwise deeper levels of nesting will fail
    // with ClassCastException of NativeArray to Object[].
    if(guardType.parameterType(guardParamCount - 1).isArray()) {
        arrayConvertingGuard = MH.filterArguments(guard, guardParamCount - 1, NativeFunction.TO_APPLY_ARGS);
    } else {
        arrayConvertingGuard = guard;
    }

    return ScriptObject.adaptHandleToVarArgCallSite(arrayConvertingGuard, descParamCount);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:ScriptFunction.java

示例3: bindToNameIfNeeded

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private static MethodHandle bindToNameIfNeeded(final MethodHandle methodHandle, final String bindName) {
    if (bindName == null) {
        return methodHandle;
    }

    // if it is vararg method, we need to extend argument array with
    // a new zeroth element that is set to bindName value.
    final MethodType methodType = methodHandle.type();
    final int parameterCount = methodType.parameterCount();
    final boolean isVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray();

    if (isVarArg) {
        return MH.filterArguments(methodHandle, 1, MH.insertArguments(ADD_ZEROTH_ELEMENT, 1, bindName));
    }
    return MH.insertArguments(methodHandle, 1, bindName);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:ScriptFunction.java

示例4: lookupExactApplyToCall

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
 * Used to find an apply to call version that fits this callsite.
 * We cannot just, as in the normal matcher case, return e.g. (Object, Object, int)
 * for (Object, Object, int, int, int) or we will destroy the semantics and get
 * a function that, when padded with undefineds, behaves differently
 * @param type actual call site type
 * @return apply to call that perfectly fits this callsite or null if none found
 */
CompiledFunction lookupExactApplyToCall(final MethodType type) {
    for (final CompiledFunction cf : code) {
        if (!cf.isApplyToCall()) {
            continue;
        }

        final MethodType cftype = cf.type();
        if (cftype.parameterCount() != type.parameterCount()) {
            continue;
        }

        if (widen(cftype).equals(widen(type))) {
            return cf;
        }
    }

    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:ScriptFunctionData.java

示例5: bindToNameIfNeeded

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private static MethodHandle bindToNameIfNeeded(final MethodHandle methodHandle, final String bindName) {
    if (bindName == null) {
        return methodHandle;
    }

    // if it is vararg method, we need to extend argument array with
    // a new zeroth element that is set to bindName value.
    final MethodType methodType = methodHandle.type();
    final int parameterCount = methodType.parameterCount();

    if (parameterCount < 2) {
        return methodHandle; // method does not have enough parameters
    }
    final boolean isVarArg = methodType.parameterType(parameterCount - 1).isArray();

    if (isVarArg) {
        return MH.filterArguments(methodHandle, 1, MH.insertArguments(ADD_ZEROTH_ELEMENT, 1, bindName));
    }
    return MH.insertArguments(methodHandle, 1, bindName);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ScriptFunction.java

示例6: testCountedLoopBodyParameters

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
@Test(dataProvider = "countedLoopBodyParameters")
public static void testCountedLoopBodyParameters(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable {
    MethodHandle loop = MethodHandles.countedLoop(
            MethodHandles.empty(countType),
            initType == null ? null : MethodHandles.empty(initType),
            MethodHandles.empty(bodyType));
    // The rule:  If body takes the minimum number of parameters, then take what countType offers.
    // The initType has to just roll with whatever the other two agree on.
    int innerParams = (bodyType.returnType() == void.class ? 1 : 2);
    MethodType expectType = bodyType.dropParameterTypes(0, innerParams);
    if (expectType.parameterCount() == 0)
        expectType = expectType.insertParameterTypes(0, countType.parameterList());
    assertEquals(expectType, loop.type());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:LoopCombinatorTest.java

示例7: needsCallee

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
static boolean needsCallee(final MethodType type) {
    final int length = type.parameterCount();

    if (length == 0) {
        return false;
    }

    final Class<?> param0 = type.parameterType(0);
    return param0 == ScriptFunction.class || param0 == boolean.class && length > 1 && type.parameterType(1) == ScriptFunction.class;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ScriptFunctionData.java

示例8: getGuardedInvocation

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final Object self = linkRequest.getReceiver();
    final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
    if (self instanceof ConsString) {
        // In order to treat ConsString like a java.lang.String we need a link request with a string receiver.
        final Object[] arguments = linkRequest.getArguments();
        arguments[0] = "";
        final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments);
        final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices);
        // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings.
        return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING);
    }

    if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
        // Support dyn:call on any object that supports some @FunctionalInterface
        // annotated interface. This way Java method, constructor references or
        // implementations of java.util.function.* interfaces can be called as though
        // those are script functions.
        final Method m = getFunctionalInterfaceMethod(self.getClass());
        if (m != null) {
            final MethodType callType = desc.getMethodType();
            // 'callee' and 'thiz' passed from script + actual arguments
            if (callType.parameterCount() != m.getParameterCount() + 2) {
                throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
            }
            return new GuardedInvocation(
                    // drop 'thiz' passed from the script.
                    MH.dropArguments(desc.getLookup().unreflect(m), 1, callType.parameterType(1)),
                    Guards.getInstanceOfGuard(m.getDeclaringClass())).asTypeSafeReturn(
                            new NashornBeansLinkerServices(linkerServices), callType);
        }
    }
    return getGuardedInvocation(beansLinker, linkRequest, linkerServices);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:NashornBeansLinker.java

示例9: invoke

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private void invoke(String method, Object logger, MethodType mt, Object... args) {
    try {
        final int last = mt.parameterCount()-1;
        boolean isVarargs = mt.parameterType(last).isArray();
        final MethodHandle handle = lookup.findVirtual(definingClass,
                method, mt).bindTo(logger);

        final StringBuilder builder = new StringBuilder();
        builder.append(logger.getClass().getSimpleName()).append('.')
                .append(method).append('(');
        String sep = "";
        int offset = 0;
        Object[] params = args;
        for (int i=0; (i-offset) < params.length; i++) {
            if (isVarargs && i == last) {
                offset = last;
                params = (Object[])args[i];
                if (params == null) break;
            }
            Object p = params[i - offset];
            String quote = (p instanceof String) ? "\"" : "";
            builder.append(sep).append(quote).append(p).append(quote);
            sep = ", ";
        }
        builder.append(')');
        if (verbose) {
            System.out.println(builder);
        }
        handle.invokeWithArguments(args);
    } catch (Throwable ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:LoggerFinderBackendTest.java

示例10: test

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
static void test(String name, MethodHandle mh) throws Throwable {
    if (VERBOSE)
        System.out.println("mh = "+name+" : "+mh+" { "
                           +Arrays.toString(junkArgs(mh.type().parameterArray())));
    int testCases0 = testCases;
    if (!mh.isVarargsCollector()) {
        // normal case
        testPermutations(mh);
    } else {
        // varargs case; add params up to MAX_ARITY
        MethodType mt = mh.type();
        int posArgs = mt.parameterCount() - 1;
        int arity0 = Math.max(3, posArgs);
        for (int arity = arity0; arity <= MAX_ARITY; arity++) {
            MethodHandle mh1;
            try {
                mh1 = adjustArity(mh, arity);
            } catch (IllegalArgumentException ex) {
                System.out.println("*** mh = "+name+" : "+mh+"; arity = "+arity+" => "+ex);
                ex.printStackTrace(System.out);
                break;  // cannot get this arity for this type
            }
            test("("+arity+")"+name, mh1);
            arity = jump(arity, arity0*2, MAX_ARITY);
        }
    }
    if (VERBOSE)
        System.out.println("ran "+(testCases - testCases0)+" test cases for "+name+" }");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:PermuteArgsTest.java

示例11: toTypeWithoutCallee

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private static Type[] toTypeWithoutCallee(final MethodType type, final int thisIndex) {
    final int paramCount = type.parameterCount();
    final Type[] t = new Type[paramCount - thisIndex];
    for(int i = thisIndex; i < paramCount; ++i) {
        t[i - thisIndex] = Type.typeFor(type.parameterType(i));
    }
    return t;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:CompiledFunction.java

示例12: TypeMap

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
 * Constructor
 * @param functionNodeId function node id
 * @param type           method type found at runtime corresponding to parameter guess
 * @param needsCallee    does the function using this type map need a callee
 */
public TypeMap(final int functionNodeId, final MethodType type, final boolean needsCallee) {
    final Type[] types = new Type[type.parameterCount()];
    int pos = 0;
    for (final Class<?> p : type.parameterArray()) {
        types[pos++] = Type.typeFor(p);
    }

    this.functionNodeId = functionNodeId;
    this.paramTypes = types;
    this.returnType = Type.typeFor(type.returnType());
    this.needsCallee = needsCallee;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TypeMap.java

示例13: typeMatchesDescription

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private static boolean typeMatchesDescription(final String paramTypes, final MethodType type) {
    final StringTokenizer tok = new StringTokenizer(paramTypes, ", ");
    for(int i = 1; i < type.parameterCount(); ++i) { // i = 1 as we ignore the receiver
        if(!(tok.hasMoreTokens() && typeNameMatches(tok.nextToken(), type.parameterType(i)))) {
            return false;
        }
    }
    return !tok.hasMoreTokens();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:SingleDynamicMethod.java

示例14: TypeMap

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
 * Constructor
 * @param functionNodeId function node id
 * @param type           method type found at runtime corresponding to parameter guess
 * @param needsCallee    does the function using this type map need a callee
 */
public TypeMap(final int functionNodeId, final MethodType type, final boolean needsCallee) {
    final Type[] types = new Type[type.parameterCount()];
    int pos = 0;
    for (final Class<?> p : type.parameterArray()) {
        types[pos++] = Type.typeFor(p);
    }
    paramTypeMap.put(functionNodeId, types);
    returnTypeMap.put(functionNodeId, Type.typeFor(type.returnType()));

    this.needsCallee = needsCallee;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:TypeMap.java

示例15: isNullConversion

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
 * True if a method handle can receive a call under a slightly different
 * method type, without moving or reformatting any stack elements.
 *
 * @param call the type of call being made
 * @param recv the type of the method handle receiving the call
 * @return whether the retyping can be done without motion or reformatting
 */
public static boolean isNullConversion(MethodType call, MethodType recv, boolean keepInterfaces) {
    if (call == recv)  return true;
    int len = call.parameterCount();
    if (len != recv.parameterCount())  return false;
    for (int i = 0; i < len; i++)
        if (!isNullConversion(call.parameterType(i), recv.parameterType(i), keepInterfaces))
            return false;
    return isNullConversion(recv.returnType(), call.returnType(), keepInterfaces);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:VerifyType.java


注:本文中的java.lang.invoke.MethodType.parameterCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。