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


Java MethodHandles.arrayElementSetter方法代码示例

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


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

示例1: lookupArrayStore

import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
/**
 * Returns a method handle to do an array store.
 * @param receiverClass Class of the array to store the value in
 * @return a MethodHandle that accepts the receiver as first argument, the index as second argument,
 *   and the value to set as 3rd argument. Return value is undefined and should be ignored.
 */
static MethodHandle lookupArrayStore(Class<?> receiverClass) {
    if (receiverClass.isArray()) {
        return MethodHandles.arrayElementSetter(receiverClass);
    } else if (Map.class.isAssignableFrom(receiverClass)) {
        // maps allow access like mymap[key]
        return MAP_PUT;
    } else if (List.class.isAssignableFrom(receiverClass)) {
        return LIST_SET;
    }
    throw new IllegalArgumentException("Attempting to address a non-array type " +
                                       "[" + receiverClass.getCanonicalName() + "] as an array.");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:Def.java

示例2: arrayElementSetter

import java.lang.invoke.MethodHandles; //导入方法依赖的package包/类
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
    final MethodHandle mh = MethodHandles.arrayElementSetter(type);
    return debug(mh, "arrayElementSetter", type);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:MethodHandleFactory.java

示例3: getElementSetter

import java.lang.invoke.MethodHandles; //导入方法依赖的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.MethodHandles.arrayElementSetter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。