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


Java MethodType.parameterType方法代码示例

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


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

示例1: PIC

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
PIC(Lookup lookup, String name, MethodType type, int initialDepth, int flavor, Object[] args) {
    super(type);
    if (type.parameterType(0) != Object.class) {
        throw new BootstrapMethodError("The receiver type (1st arg) of invokedynamic descriptor must be Object.");
    }
    this.lookup = lookup;
    this.name = name;
    this.flavor = flavor;
    this.args = args;
    this.depth = initialDepth;

    MethodHandle fallback = FALLBACK.bindTo(this)
      .asCollector(Object[].class, type.parameterCount())
      .asType(type);

    setTarget(fallback);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:DefBootstrap.java

示例2: findFastSetIndexMethod

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
 * Return a fast linked array setter, or null if we have to dispatch to super class
 * @param desc     descriptor
 * @param request  link request
 * @return invocation or null if needs to be sent to slow relink
 */
@Override
public GuardedInvocation findFastSetIndexMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) { // array, index, value
    final MethodType callType    = desc.getMethodType();
    final Class<?>   indexType   = callType.parameterType(1);
    final Class<?>   elementType = callType.parameterType(2);

    if (ContinuousArrayData.class.isAssignableFrom(clazz) && indexType == int.class) {
        final Object[]        args  = request.getArguments();
        final int             index = (int)args[args.length - 2];

        if (hasRoomFor(index)) {
            MethodHandle setElement = getElementSetter(elementType); //Z(continuousarraydata, int, int), return true if successful
            if (setElement != null) {
                //else we are dealing with a wider type than supported by this callsite
                MethodHandle getArray = ScriptObject.GET_ARRAY.methodHandle();
                getArray   = MH.asType(getArray, getArray.type().changeReturnType(getClass()));
                setElement = MH.filterArguments(setElement, 0, getArray);
                final MethodHandle guard = MH.insertArguments(FAST_ACCESS_GUARD, 0, clazz);
                return new GuardedInvocation(setElement, guard, (SwitchPoint)null, ClassCastException.class); //CCE if not a scriptObject anymore
            }
        }
    }

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

示例3: findFastGetIndexMethod

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
 * Return a fast linked array getter, or null if we have to dispatch to super class
 * @param desc     descriptor
 * @param request  link request
 * @return invocation or null if needs to be sent to slow relink
 */
@Override
public GuardedInvocation findFastGetIndexMethod(final Class<? extends ArrayData> clazz, final CallSiteDescriptor desc, final LinkRequest request) {
    final MethodType callType   = desc.getMethodType();
    final Class<?>   indexType  = callType.parameterType(1);
    final Class<?>   returnType = callType.returnType();

    if (ContinuousArrayData.class.isAssignableFrom(clazz) && indexType == int.class) {
        final Object[] args  = request.getArguments();
        final int      index = (int)args[args.length - 1];

        if (has(index)) {
            final MethodHandle getArray     = ScriptObject.GET_ARRAY.methodHandle();
            final int          programPoint = NashornCallSiteDescriptor.isOptimistic(desc) ? NashornCallSiteDescriptor.getProgramPoint(desc) : INVALID_PROGRAM_POINT;
            MethodHandle       getElement   = getElementGetter(returnType, programPoint);
            if (getElement != null) {
                getElement = MH.filterArguments(getElement, 0, MH.asType(getArray, getArray.type().changeReturnType(clazz)));
                final MethodHandle guard = MH.insertArguments(FAST_ACCESS_GUARD, 0, clazz);
                return new GuardedInvocation(getElement, guard, (SwitchPoint)null, ClassCastException.class);
            }
        }
    }

    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:ContinuousArrayData.java

示例4: CatchExceptionTest

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
public CatchExceptionTest(TestCase testCase, final boolean isVararg, final int argsCount,
        final int catchDrops) {
    this.testCase = testCase;
    this.dropped = catchDrops;
    MethodHandle thrower = testCase.thrower;
    int throwerLen = thrower.type().parameterCount();
    List<Class<?>> classes;
    int extra = Math.max(0, argsCount - throwerLen);
    classes = getThrowerParams(isVararg, extra);
    this.argsCount = throwerLen + classes.size();
    thrower = Helper.addTrailingArgs(thrower, this.argsCount, classes);
    if (isVararg && argsCount > throwerLen) {
        MethodType mt = thrower.type();
        Class<?> lastParam = mt.parameterType(mt.parameterCount() - 1);
        thrower = thrower.asVarargsCollector(lastParam);
    }
    this.thrower = thrower;
    this.dropped = Math.min(this.argsCount, catchDrops);
    catcher = testCase.getCatcher(getCatcherParams());
    nargs = Math.max(2, this.argsCount);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:CatchExceptionTest.java

示例5: adjustArity

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
static MethodHandle adjustArity(MethodHandle mh, int arity) {
    MethodType mt = mh.type();
    int posArgs = mt.parameterCount() - 1;
    Class<?> reptype = mt.parameterType(posArgs).getComponentType();
    MethodType mt1 = mt.dropParameterTypes(posArgs, posArgs+1);
    while (mt1.parameterCount() < arity) {
        Class<?> pt = reptype;
        if (pt == Object.class && posArgs > 0)
            // repeat types cyclically if possible:
            pt = mt1.parameterType(mt1.parameterCount() - posArgs);
        mt1 = mt1.appendParameterTypes(pt);
    }
    try {
        return mh.asType(mt1);
    } catch (WrongMethodTypeException | IllegalArgumentException ex) {
        throw new IllegalArgumentException("cannot convert to type "+mt1+" from "+mh, ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:PermuteArgsTest.java

示例6: widen

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private static MethodType widen(final MethodType cftype) {
    final Class<?>[] paramTypes = new Class<?>[cftype.parameterCount()];
    for (int i = 0; i < cftype.parameterCount(); i++) {
        paramTypes[i] = cftype.parameterType(i).isPrimitive() ? cftype.parameterType(i) : Object.class;
    }
    return MH.type(cftype.returnType(), paramTypes);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:ScriptFunctionData.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:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:ScriptFunctionData.java

示例8: isOfClass

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
 * Creates a guard method handle with arguments of a specified type, but with boolean return value. When invoked, it
 * returns true if the first argument is of the specified class (exactly of it, not a subclass). The rest of the
 * arguments will be ignored.
 *
 * @param clazz the class of the first argument to test for
 * @param type the method type
 * @return a method handle testing whether its first argument is of the specified class.
 */
@SuppressWarnings("boxing")
public static MethodHandle isOfClass(final Class<?> clazz, final MethodType type) {
    final Class<?> declaredType = type.parameterType(0);
    if(clazz == declaredType) {
        LOG.log(Level.WARNING, "isOfClassGuardAlwaysTrue", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantTrue(type);
    }
    if(!declaredType.isAssignableFrom(clazz)) {
        LOG.log(Level.WARNING, "isOfClassGuardAlwaysFalse", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantFalse(type);
    }
    return getClassBoundArgumentTest(IS_OF_CLASS, clazz, 0, type);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:Guards.java

示例9: isArray

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
 * Creates a method handle that returns true if the argument in the specified position is a Java array.
 *
 * @param pos the position in the argument lit
 * @param type the method type of the handle
 * @return a method handle that returns true if the argument in the specified position is a Java array; the rest of
 * the arguments are ignored.
 */
@SuppressWarnings("boxing")
public static MethodHandle isArray(final int pos, final MethodType type) {
    final Class<?> declaredType = type.parameterType(pos);
    if(declaredType.isArray()) {
        LOG.log(Level.WARNING, "isArrayGuardAlwaysTrue", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantTrue(type);
    }
    if(!declaredType.isAssignableFrom(Object[].class)) {
        LOG.log(Level.WARNING, "isArrayGuardAlwaysFalse", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantFalse(type);
    }
    return asType(IS_ARRAY, pos, type);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:Guards.java

示例10: isInstance

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
 * Creates a method handle with arguments of a specified type, but with boolean return value. When invoked, it
 * returns true if the n'th argument is instance of the specified class or its subclass). The rest of the arguments
 * will be ignored.
 *
 * @param clazz the class of the first argument to test for
 * @param pos the position on the argument list to test
 * @param type the method type
 * @return a method handle testing whether its first argument is of the specified class or subclass.
 */
@SuppressWarnings("boxing")
public static MethodHandle isInstance(final Class<?> clazz, final int pos, final MethodType type) {
    final Class<?> declaredType = type.parameterType(pos);
    if(clazz.isAssignableFrom(declaredType)) {
        LOG.log(Level.WARNING, "isInstanceGuardAlwaysTrue", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantTrue(type);
    }
    if(!declaredType.isAssignableFrom(clazz)) {
        LOG.log(Level.WARNING, "isInstanceGuardAlwaysFalse", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() });
        return constantFalse(type);
    }
    return getClassBoundArgumentTest(IS_INSTANCE, clazz, pos, type);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:Guards.java

示例11: findCallMethod

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private static GuardedInvocation findCallMethod(final CallSiteDescriptor desc) {
    MethodHandle mh = NashornCallSiteDescriptor.isScope(desc)? JSOBJECT_SCOPE_CALL : JSOBJECT_CALL;
    if (NashornCallSiteDescriptor.isApplyToCall(desc)) {
        mh = MH.insertArguments(JSOBJECT_CALL_TO_APPLY, 0, mh);
    }
    final MethodType type = desc.getMethodType();
    mh = type.parameterType(type.parameterCount() - 1) == Object[].class ?
            mh :
            MH.asCollector(mh, Object[].class, type.parameterCount() - 2);
    return new GuardedInvocation(mh, IS_JSOBJECT_GUARD);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:JSObjectLinker.java

示例12: getParameterClass

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private static Class<?> getParameterClass(final MethodType t, final int l, final int i, final boolean varArgs) {
    return varArgs && i >= l - 1 ? t.parameterType(l - 1).getComponentType() : t.parameterType(i);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:MaximallySpecific.java

示例13: getGuardedInvocation

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
    final Object objBoundCallable = linkRequest.getReceiver();
    if(!(objBoundCallable instanceof BoundCallable)) {
        return null;
    }

    final CallSiteDescriptor descriptor = linkRequest.getCallSiteDescriptor();
    final Operation operation = NamedOperation.getBaseOperation(descriptor.getOperation());
    // We need to distinguish NEW from CALL because CALL sites have parameter list of the form
    // "callee, this, args", while NEW sites have "callee, args" -- they lack the "this" parameter.
    final boolean isCall;
    if (operation == StandardOperation.NEW) {
        isCall = false;
    } else if (operation == StandardOperation.CALL) {
        isCall = true;
    } else {
        // Only CALL and NEW are supported.
        return null;
    }
    final BoundCallable boundCallable = (BoundCallable)objBoundCallable;
    final Object callable = boundCallable.getCallable();
    final Object boundThis = boundCallable.getBoundThis();

    // We need to ask the linker services for a delegate invocation on the target callable.

    // Replace arguments (boundCallable[, this], args) => (callable[, boundThis], boundArgs, args) when delegating
    final Object[] args = linkRequest.getArguments();
    final Object[] boundArgs = boundCallable.getBoundArgs();
    final int argsLen = args.length;
    final int boundArgsLen = boundArgs.length;
    final Object[] newArgs = new Object[argsLen + boundArgsLen];
    newArgs[0] = callable;
    final int firstArgIndex;
    if (isCall) {
        newArgs[1] = boundThis;
        firstArgIndex = 2;
    } else {
        firstArgIndex = 1;
    }
    System.arraycopy(boundArgs, 0, newArgs, firstArgIndex, boundArgsLen);
    System.arraycopy(args, firstArgIndex, newArgs, firstArgIndex + boundArgsLen, argsLen - firstArgIndex);

    // Use R(T0, T1, T2, ...) => R(callable.class, boundThis.class, boundArg0.class, ..., boundArgn.class, T2, ...)
    // call site type when delegating to underlying linker (for NEW, there's no this).
    final MethodType type = descriptor.getMethodType();
    // Use R(T0, ...) => R(callable.class, ...)
    MethodType newMethodType = descriptor.getMethodType().changeParameterType(0, callable.getClass());
    if (isCall) {
        // R(callable.class, T1, ...) => R(callable.class, boundThis.class, ...)
        newMethodType = newMethodType.changeParameterType(1, boundThis == null? Object.class : boundThis.getClass());
    }
    // R(callable.class[, boundThis.class], T2, ...) => R(callable.class[, boundThis.class], boundArg0.class, ..., boundArgn.class, T2, ...)
    for(int i = boundArgs.length; i-- > 0;) {
        newMethodType = newMethodType.insertParameterTypes(firstArgIndex, boundArgs[i] == null ? Object.class : boundArgs[i].getClass());
    }
    final CallSiteDescriptor newDescriptor = descriptor.changeMethodType(newMethodType);

    // Delegate to target's linker
    final GuardedInvocation inv = linkerServices.getGuardedInvocation(linkRequest.replaceArguments(newDescriptor, newArgs));
    if(inv == null) {
        return null;
    }

    // Bind (callable[, boundThis], boundArgs) to the delegate handle
    final MethodHandle boundHandle = MethodHandles.insertArguments(inv.getInvocation(), 0,
            Arrays.copyOf(newArgs, firstArgIndex + boundArgs.length));
    final Class<?> p0Type = type.parameterType(0);
    final MethodHandle droppingHandle;
    if (isCall) {
        // Ignore incoming boundCallable and this
        droppingHandle = MethodHandles.dropArguments(boundHandle, 0, p0Type, type.parameterType(1));
    } else {
        // Ignore incoming boundCallable
        droppingHandle = MethodHandles.dropArguments(boundHandle, 0, p0Type);
    }
    // Identity guard on boundCallable object
    final MethodHandle newGuard = Guards.getIdentityGuard(boundCallable);
    return inv.replaceMethods(droppingHandle, newGuard.asType(newGuard.type().changeParameterType(0, p0Type)));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:81,代码来源:BoundCallableLinker.java

示例14: isApplicableDynamically

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private static boolean isApplicableDynamically(final LinkerServices linkerServices, final MethodType callSiteType,
        final SingleDynamicMethod m) {
    final MethodType methodType = m.getMethodType();
    final boolean varArgs = m.isVarArgs();
    final int fixedArgLen = methodType.parameterCount() - (varArgs ? 1 : 0);
    final int callSiteArgLen = callSiteType.parameterCount();

    // Arity checks
    if(varArgs) {
        if(callSiteArgLen < fixedArgLen) {
            return false;
        }
    } else if(callSiteArgLen != fixedArgLen) {
        return false;
    }

    // Fixed arguments type checks, starting from 1, as receiver type doesn't participate
    for(int i = 1; i < fixedArgLen; ++i) {
        if(!isApplicableDynamically(linkerServices, callSiteType.parameterType(i), methodType.parameterType(i))) {
            return false;
        }
    }
    if(!varArgs) {
        // Not vararg; both arity and types matched.
        return true;
    }

    final Class<?> varArgArrayType = methodType.parameterType(fixedArgLen);
    final Class<?> varArgType = varArgArrayType.getComponentType();

    if(fixedArgLen == callSiteArgLen - 1) {
        // Exactly one vararg; check both array type matching and array component type matching.
        final Class<?> callSiteArgType = callSiteType.parameterType(fixedArgLen);
        return isApplicableDynamically(linkerServices, callSiteArgType, varArgArrayType)
                || isApplicableDynamically(linkerServices, callSiteArgType, varArgType);
    }

    // Either zero, or more than one vararg; check if all actual vararg types match the vararg array component type.
    for(int i = fixedArgLen; i < callSiteArgLen; ++i) {
        if(!isApplicableDynamically(linkerServices, callSiteType.parameterType(i), varArgType)) {
            return false;
        }
    }

    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:OverloadedDynamicMethod.java

示例15: getElementSetter

import java.lang.invoke.MethodType; //导入方法依赖的package包/类
private GuardedInvocationComponent getElementSetter(final CallSiteDescriptor callSiteDescriptor,
        final LinkerServices linkerServices, final List<String> operations) throws Exception {
    final MethodType callSiteType = callSiteDescriptor.getMethodType();
    final Class<?> declaredType = callSiteType.parameterType(0);

    final GuardedInvocationComponent gic;
    // If declared type of receiver at the call site is already an array, a list or map, bind without guard. Thing
    // is, it'd be quite stupid of a call site creator to go though invokedynamic when it knows in advance they're
    // dealing with an array, or a list or map, but hey...
    // Note that for arrays and lists, using LinkerServices.asType() will ensure that any language specific linkers
    // in use will get a chance to perform any (if there's any) implicit conversion to integer for the indices.
    final boolean isMap;
    if(declaredType.isArray()) {
        gic = new GuardedInvocationComponent(MethodHandles.arrayElementSetter(declaredType));
        isMap = false;
    } else if(List.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(SET_LIST_ELEMENT);
        isMap = false;
    } else if(Map.class.isAssignableFrom(declaredType)) {
        gic = new GuardedInvocationComponent(PUT_MAP_ELEMENT);
        isMap = true;
    } else if(clazz.isArray()) {
        gic = getClassGuardedInvocationComponent(MethodHandles.arrayElementSetter(clazz), callSiteType);
        isMap = false;
    } else if(List.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(SET_LIST_ELEMENT, Guards.asType(LIST_GUARD, callSiteType), List.class,
                ValidationType.INSTANCE_OF);
        isMap = false;
    } else if(Map.class.isAssignableFrom(clazz)) {
        gic = new GuardedInvocationComponent(PUT_MAP_ELEMENT, Guards.asType(MAP_GUARD, callSiteType), Map.class,
                ValidationType.INSTANCE_OF);
        isMap = true;
    } else {
        // Can't set elements for objects that are neither arrays, nor list, nor maps.
        gic = null;
        isMap = false;
    }

    // In contrast to, say, getElementGetter, we only compute the nextComponent if the target object is not a map,
    // as maps will always succeed in setting the element and will never need to fall back to the next component
    // operation.
    final GuardedInvocationComponent nextComponent = isMap ? null : getGuardedInvocationComponent(
            callSiteDescriptor, linkerServices, operations);
    if(gic == null) {
        return nextComponent;
    }

    // We can have "dyn:setElem:foo", especially in composites, i.e. "dyn:setElem|setProp:foo"
    final String fixedKey = getFixedKey(callSiteDescriptor);
    // Convert the key to a number if we're working with a list or array
    final Object typedFixedKey;
    if(!isMap && fixedKey != null) {
        typedFixedKey = convertKeyToInteger(fixedKey, linkerServices);
        if(typedFixedKey == null) {
            // key is not numeric, it can never succeed
            return nextComponent;
        }
    } else {
        typedFixedKey = fixedKey;
    }

    final GuardedInvocation gi = gic.getGuardedInvocation();
    final Binder binder = new Binder(linkerServices, callSiteType, typedFixedKey);
    final MethodHandle invocation = gi.getInvocation();

    if(nextComponent == null) {
        return gic.replaceInvocation(binder.bind(invocation));
    }

    final MethodHandle checkGuard = convertArgToInt(invocation == SET_LIST_ELEMENT ? RANGE_CHECK_LIST :
        RANGE_CHECK_ARRAY, linkerServices, callSiteDescriptor);
    final MethodPair matchedInvocations = matchReturnTypes(binder.bind(invocation),
            nextComponent.getGuardedInvocation().getInvocation());
    return nextComponent.compose(matchedInvocations.guardWithTest(binder.bindTest(checkGuard)), gi.getGuard(),
            gic.getValidatorClass(), gic.getValidationType());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:77,代码来源:BeanLinker.java


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