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


Java GeneratorAdapter.unbox方法代码示例

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


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

示例1: unbox

import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
/**
 * Generates unboxing bytecode for the passed type. An {@link Object} is expected to be on the
 * stack when these bytecodes are inserted.
 *
 * ASM takes a short cut when dealing with short/byte types and convert them into int rather
 * than short/byte types. This is not an issue on the jvm nor Android's ART but it is an issue
 * on Dalvik.
 *
 * @param mv the {@link GeneratorAdapter} generating a method implementation.
 * @param type the expected un-boxed type.
 */
public static void unbox(GeneratorAdapter mv, Type type) {
    if (type.equals(Type.SHORT_TYPE)) {
        mv.checkCast(NUMBER_TYPE);
        mv.invokeVirtual(NUMBER_TYPE, SHORT_VALUE);
    } else if (type.equals(Type.BYTE_TYPE)) {
        mv.checkCast(NUMBER_TYPE);
        mv.invokeVirtual(NUMBER_TYPE, BYTE_VALUE);
    } else {
        mv.unbox(type);
    }
}
 
开发者ID:Idtk,项目名称:Hotfix,代码行数:23,代码来源:ByteCodeUtils.java

示例2: loadArguments

import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
@Contract("null, null, null, !null -> fail")
private static void loadArguments(GeneratorAdapter ga, Type[] interfaceTypes, Type[] targetTypes, boolean isTargetPublic) {
    Ensure.ensureCondition(interfaceTypes.length == targetTypes.length,
            "Interface and target parameter count don't match!");
    /* Iterate through all types */
    for(int i = 0; i < interfaceTypes.length; i++) {
        Type interfaceType = interfaceTypes[i];
        Type targetType = targetTypes[i];

        ga.loadArg(i);

        /* Do not do boxing/unboxing if MethodHandle.invoke is used, it handles them on its own */
        if(!isTargetPublic) continue;

        if(isPrimitive(interfaceType)) {
            if(!isPrimitive(targetType)) {
                ga.box(targetType);
            }
        } else {
            if(isPrimitive(targetType)) {
                ga.unbox(targetType);
            } else {
                if(interfaceType.equals(OBJECT)) {
                    ga.checkCast(targetType);
                    ga.cast(interfaceType, targetType);
                }
            }
        }
    }
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:31,代码来源:MethodGenerator.java

示例3: handleReturn

import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
@Contract("null, null, null -> fail")
private static void handleReturn(GeneratorAdapter ga, Method interfaceMethod, Type targetReturnType) {
    Type returnType = Type.getReturnType(interfaceMethod);

    if(isPrimitive(returnType)) {
        if(!isPrimitive(targetReturnType)) {
            ga.unbox(targetReturnType);
        }
    } else {
        if(isPrimitive(targetReturnType)) {
            ga.box(targetReturnType);
        }
    }
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:15,代码来源:MethodGenerator.java

示例4: emitBody

import org.objectweb.asm.commons.GeneratorAdapter; //导入方法依赖的package包/类
static void emitBody(ObjExpr objx, GeneratorAdapter gen, Class retClass, Expr body) {
		MaybePrimitiveExpr be = (MaybePrimitiveExpr) body;
		if(Util.isPrimitive(retClass) && be.canEmitPrimitive())
			{
			Class bc = maybePrimitiveType(be);
			if(bc == retClass)
				be.emitUnboxed(C.RETURN, objx, gen);
			else if(retClass == long.class && bc == int.class)
				{
				be.emitUnboxed(C.RETURN, objx, gen);
				gen.visitInsn(I2L);
				}
			else if(retClass == double.class && bc == float.class)
				{
				be.emitUnboxed(C.RETURN, objx, gen);
				gen.visitInsn(F2D);
				}
			else if(retClass == int.class && bc == long.class)
				{
				be.emitUnboxed(C.RETURN, objx, gen);
				gen.invokeStatic(RT_TYPE, Method.getMethod("int intCast(long)"));
				}
			else if(retClass == float.class && bc == double.class)
				{
				be.emitUnboxed(C.RETURN, objx, gen);
				gen.visitInsn(D2F);
				}
			else
				throw new IllegalArgumentException("Mismatched primitive return, expected: "
				                                   + retClass + ", had: " + be.getJavaClass());
			}
		else
			{
			body.emit(C.RETURN, objx, gen);
			if(retClass == void.class)
				{
				gen.pop();
				}
			else
				gen.unbox(Type.getType(retClass));
			}
}
 
开发者ID:mrange,项目名称:fsharpadvent2016,代码行数:43,代码来源:Compiler.java


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