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


Java Wrapper.values方法代码示例

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


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

示例1: testNullRef2Prim

import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
/**
 * Tests that null wrapper reference is successfully converted to primitive
 * types. Converted result should be zero for a primitive. Bug 8060483.
 */
public static void testNullRef2Prim() {
    for (Wrapper from : Wrapper.values()) {
        for (Wrapper to : Wrapper.values()) {
            if (from == Wrapper.VOID || to == Wrapper.VOID) {
                continue;
            }
            // MHs.eCA javadoc:
            //    If T0 is a reference and T1 a primitive, and if the reference
            //    is null at runtime, a zero value is introduced.
            for (TestConversionMode mode : TestConversionMode.values()) {
                testConversion(mode, from.wrapperType(),
                        to.primitiveType(), null, to.zero(), false, null);
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:ExplicitCastArgumentsTest.java

示例2: testRef2Prim

import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
/**
 * Tests that non-null wrapper reference is successfully converted to
 * primitive types.
 */
public static void testRef2Prim() {
    for (Wrapper from : Wrapper.values()) {
        for (Wrapper to : Wrapper.values()) {
            if (from == Wrapper.VOID || to == Wrapper.VOID
                    || to == Wrapper.OBJECT) {
                continue;
            }
            Object value = RANDOM_VALUES.get(from);
            for (TestConversionMode mode : TestConversionMode.values()) {
                if (from != Wrapper.OBJECT) {
                    Object convValue = to.wrap(value);
                    testConversion(mode, from.wrapperType(),
                            to.primitiveType(), value, convValue, false, null);
                } else {
                    testConversion(mode, from.wrapperType(),
                            to.primitiveType(), value, null,
                            true, ClassCastException.class);
                }
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:ExplicitCastArgumentsTest.java

示例3: testPrim2Prim

import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
/**
 * Tests that primitive is successfully converted to other primitive type.
 */
public static void testPrim2Prim() {
    for (Wrapper from : Wrapper.values()) {
        for (Wrapper to : Wrapper.values()) {
            if (from == Wrapper.VOID || to == Wrapper.VOID
                    || from == Wrapper.OBJECT || to == Wrapper.OBJECT) {
                continue;
            }
            Object value = RANDOM_VALUES.get(from);
            Object convValue = to.wrap(value);
            for (TestConversionMode mode : TestConversionMode.values()) {
                testConversion(mode, from.primitiveType(),
                        to.primitiveType(), value, convValue, false, null);
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:ExplicitCastArgumentsTest.java

示例4: testBox

import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
@Test
public void testBox() throws Throwable {
    for (Wrapper w : Wrapper.values()) {
        if (w == Wrapper.VOID)    continue;  // skip this; no unboxed form
        if (w == Wrapper.OBJECT)  continue;  // skip this; already unboxed
        for (int n = -5; n < 10; n++) {
            Object box = w.wrap(n);
            MethodHandle boxer = ValueConversions.boxExact(w);
            Object expResult = box;
            Object result = null;
            switch (w) {
                case INT:     result = (Integer) boxer.invokeExact(/*int*/n); break;
                case LONG:    result = (Long)    boxer.invokeExact((long)n); break;
                case FLOAT:   result = (Float)   boxer.invokeExact((float)n); break;
                case DOUBLE:  result = (Double)  boxer.invokeExact((double)n); break;
                case CHAR:    result = (Character) boxer.invokeExact((char)n); break;
                case BYTE:    result = (Byte)    boxer.invokeExact((byte)n); break;
                case SHORT:   result = (Short)   boxer.invokeExact((short)n); break;
                case BOOLEAN: result = (Boolean) boxer.invokeExact((n & 1) != 0); break;
            }
            assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box),
                         expResult, result);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:ValueConversionsTest.java

示例5: testConvert

import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
@Test
public void testConvert() throws Throwable {
    for (long tval = 0, ctr = 0;;) {
        if (++ctr > 99999)  throw new AssertionError("too many test values");
        // prints 3776 test patterns (3776 = 8*59*8)
        tval = nextTestValue(tval);
        if (tval == 0) {
            break;  // repeat
        }
    }
    for (Wrapper src : Wrapper.values()) {
        for (Wrapper dst : Wrapper.values()) {
            testConvert(src, dst, 0);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:ValueConversionsTest.java

示例6: testPrim2Ref

import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
/**
 * Tests that primitive is successfully converted to wrapper reference
 * types, to the Number type (if possible) and to the Object type.
 */
public static void testPrim2Ref() {
    for (Wrapper from : Wrapper.values()) {
        for (Wrapper to : Wrapper.values()) {
            if (from == Wrapper.VOID || from == Wrapper.OBJECT
                    || to == Wrapper.VOID || to == Wrapper.OBJECT) {
                continue;
            }
            Object value = RANDOM_VALUES.get(from);
            for (TestConversionMode mode : TestConversionMode.values()) {
                if (from == to) {
                    testConversion(mode, from.primitiveType(),
                            to.wrapperType(), value, value, false, null);
                } else {
                    testConversion(mode, from.primitiveType(),
                            to.wrapperType(), value, null, true, ClassCastException.class);
                }
                if (from != Wrapper.BOOLEAN && from != Wrapper.CHAR) {
                    testConversion(mode, from.primitiveType(),
                            Number.class, value, value, false, null);
                } else {
                    testConversion(mode, from.primitiveType(),
                            Number.class, value, null,
                            true, ClassCastException.class);
                }
                testConversion(mode, from.primitiveType(),
                        Object.class, value, value, false, null);
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:ExplicitCastArgumentsTest.java

示例7: testReturnAny2Void

import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
/**
 * Tests that non-null any return is successfully converted to non-type
 * void.
 */
public static void testReturnAny2Void() {
    for (Wrapper from : Wrapper.values()) {
        testConversion(TestConversionMode.RETURN_VALUE, from.wrapperType(),
                void.class, RANDOM_VALUES.get(from),
                null, false, null);
        testConversion(TestConversionMode.RETURN_VALUE, from.primitiveType(),
                void.class, RANDOM_VALUES.get(from),
                null, false, null);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:ExplicitCastArgumentsTest.java

示例8: testReturnVoid2Any

import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
/**
 * Tests that void return is successfully converted to primitive and
 * reference. Result should be zero for primitives and null for references.
 */
public static void testReturnVoid2Any() {
    for (Wrapper to : Wrapper.values()) {
        testConversion(TestConversionMode.RETURN_VALUE, void.class,
                to.primitiveType(), null,
                to.zero(), false, null);
        testConversion(TestConversionMode.RETURN_VALUE, void.class,
                to.wrapperType(), null,
                null, false, null);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:ExplicitCastArgumentsTest.java

示例9: testUnbox

import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
private void testUnbox(boolean doCast) throws Throwable {
    for (Wrapper dst : Wrapper.values()) {
        for (Wrapper src : Wrapper.values()) {
            testUnbox(doCast, dst, src);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:ValueConversionsTest.java

示例10: makePreparedFieldLambdaForm

import sun.invoke.util.Wrapper; //导入方法依赖的package包/类
private static LambdaForm makePreparedFieldLambdaForm(byte formOp, boolean isVolatile, int ftypeKind) {
    boolean isGetter  = (formOp & 1) == (AF_GETFIELD & 1);
    boolean isStatic  = (formOp >= AF_GETSTATIC);
    boolean needsInit = (formOp >= AF_GETSTATIC_INIT);
    boolean needsCast = (ftypeKind == FT_CHECKED_REF);
    Wrapper fw = (needsCast ? Wrapper.OBJECT : Wrapper.values()[ftypeKind]);
    Class<?> ft = fw.primitiveType();
    assert(ftypeKind(needsCast ? String.class : ft) == ftypeKind);
    String tname  = fw.primitiveSimpleName();
    String ctname = Character.toUpperCase(tname.charAt(0)) + tname.substring(1);
    if (isVolatile)  ctname += "Volatile";
    String getOrPut = (isGetter ? "get" : "put");
    String linkerName = (getOrPut + ctname);  // getObject, putIntVolatile, etc.
    MethodType linkerType;
    if (isGetter)
        linkerType = MethodType.methodType(ft, Object.class, long.class);
    else
        linkerType = MethodType.methodType(void.class, Object.class, long.class, ft);
    MemberName linker = new MemberName(Unsafe.class, linkerName, linkerType, REF_invokeVirtual);
    try {
        linker = IMPL_NAMES.resolveOrFail(REF_invokeVirtual, linker, null, NoSuchMethodException.class);
    } catch (ReflectiveOperationException ex) {
        throw newInternalError(ex);
    }

    // What is the external type of the lambda form?
    MethodType mtype;
    if (isGetter)
        mtype = MethodType.methodType(ft);
    else
        mtype = MethodType.methodType(void.class, ft);
    mtype = mtype.basicType();  // erase short to int, etc.
    if (!isStatic)
        mtype = mtype.insertParameterTypes(0, Object.class);
    final int DMH_THIS  = 0;
    final int ARG_BASE  = 1;
    final int ARG_LIMIT = ARG_BASE + mtype.parameterCount();
    // if this is for non-static access, the base pointer is stored at this index:
    final int OBJ_BASE  = isStatic ? -1 : ARG_BASE;
    // if this is for write access, the value to be written is stored at this index:
    final int SET_VALUE  = isGetter ? -1 : ARG_LIMIT - 1;
    int nameCursor = ARG_LIMIT;
    final int F_HOLDER  = (isStatic ? nameCursor++ : -1);  // static base if any
    final int F_OFFSET  = nameCursor++;  // Either static offset or field offset.
    final int OBJ_CHECK = (OBJ_BASE >= 0 ? nameCursor++ : -1);
    final int INIT_BAR  = (needsInit ? nameCursor++ : -1);
    final int PRE_CAST  = (needsCast && !isGetter ? nameCursor++ : -1);
    final int LINKER_CALL = nameCursor++;
    final int POST_CAST = (needsCast && isGetter ? nameCursor++ : -1);
    final int RESULT    = nameCursor-1;  // either the call or the cast
    Name[] names = arguments(nameCursor - ARG_LIMIT, mtype.invokerType());
    if (needsInit)
        names[INIT_BAR] = new Name(Lazy.NF_ensureInitialized, names[DMH_THIS]);
    if (needsCast && !isGetter)
        names[PRE_CAST] = new Name(Lazy.NF_checkCast, names[DMH_THIS], names[SET_VALUE]);
    Object[] outArgs = new Object[1 + linkerType.parameterCount()];
    assert(outArgs.length == (isGetter ? 3 : 4));
    outArgs[0] = UNSAFE;
    if (isStatic) {
        outArgs[1] = names[F_HOLDER]  = new Name(Lazy.NF_staticBase, names[DMH_THIS]);
        outArgs[2] = names[F_OFFSET]  = new Name(Lazy.NF_staticOffset, names[DMH_THIS]);
    } else {
        outArgs[1] = names[OBJ_CHECK] = new Name(Lazy.NF_checkBase, names[OBJ_BASE]);
        outArgs[2] = names[F_OFFSET]  = new Name(Lazy.NF_fieldOffset, names[DMH_THIS]);
    }
    if (!isGetter) {
        outArgs[3] = (needsCast ? names[PRE_CAST] : names[SET_VALUE]);
    }
    for (Object a : outArgs)  assert(a != null);
    names[LINKER_CALL] = new Name(linker, outArgs);
    if (needsCast && isGetter)
        names[POST_CAST] = new Name(Lazy.NF_checkCast, names[DMH_THIS], names[LINKER_CALL]);
    for (Name n : names)  assert(n != null);
    String fieldOrStatic = (isStatic ? "Static" : "Field");
    String lambdaName = (linkerName + fieldOrStatic);  // significant only for debugging
    if (needsCast)  lambdaName += "Cast";
    if (needsInit)  lambdaName += "Init";
    return new LambdaForm(lambdaName, ARG_LIMIT, names, RESULT);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:80,代码来源:DirectMethodHandle.java


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