當前位置: 首頁>>代碼示例>>Java>>正文


Java GeneratorAdapter.visitLdcInsn方法代碼示例

本文整理匯總了Java中org.objectweb.asm.commons.GeneratorAdapter.visitLdcInsn方法的典型用法代碼示例。如果您正苦於以下問題:Java GeneratorAdapter.visitLdcInsn方法的具體用法?Java GeneratorAdapter.visitLdcInsn怎麽用?Java GeneratorAdapter.visitLdcInsn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.objectweb.asm.commons.GeneratorAdapter的用法示例。


在下文中一共展示了GeneratorAdapter.visitLdcInsn方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visitx

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
private void visitx(GeneratorAdapter mv, List<String> strings) {
    if (strings.size() == 1) {
        visitCase(strings.get(0));
        return;
    }
    for (String string : strings) {
        Label label = new Label();
        visitString();
        mv.visitLdcInsn(string);
        mv.invokeVirtual(STRING_TYPE, Method.getMethod("boolean equals(Object)"));
        mv.visitJumpInsn(Opcodes.IFEQ, label);
        visitCase(string);
        mv.visitLabel(label);
    }

    visitDefault();
}
 
開發者ID:meili,項目名稱:Aceso,代碼行數:18,代碼來源:IntSwitch.java

示例2: visitx

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
 * Emit code for a string if-else block.
 *
 *     if (s.equals("collided_method1")) {
 *         visit(s);
 *     } else if (s.equals("collided_method2")) {
 *         visit(s);
 *     }
 *
 * In the most common case of just one string, this degenerates to:
 *
 *      visit(s)
 *
 */
private void visitx(GeneratorAdapter mv, List<String> strings) {
    if (strings.size() == 1) {
        visitCase(strings.get(0));
        return;
    }
    for (int i = 0; i < strings.size(); ++i) {
        String string = strings.get(i);
        Label label = new Label();
        visitString();
        mv.visitLdcInsn(string);
        mv.invokeVirtual(STRING_TYPE, Method.getMethod("boolean equals(Object)"));
        mv.visitJumpInsn(Opcodes.IFEQ, label);
        visitCase(string);
        mv.visitLabel(label);
    }

    visitDefault();
}
 
開發者ID:dodola,項目名稱:AnoleFix,代碼行數:33,代碼來源:StringSwitch.java

示例3: redirectLocal

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
 * Pushes in the stack the value that should be redirected for the given local.
 */
protected static void redirectLocal(GeneratorAdapter mv, Type arg) {
    switch (arg.getDescriptor()) {
        case "Z":
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
            break;
        case "B":
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Byte", "TYPE", "Ljava/lang/Class;");
            break;
        case "C":
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;");
            break;
        case "S":
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
            break;
        case "I":
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;");
            break;
        case "F":
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;");
            break;
        case "D":
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;");
            break;
        case "J":
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
            break;
        case "V":
            mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;");
            break;
        default:
            mv.visitLdcInsn(Type.getType(arg.getDescriptor()));
    }

}
 
開發者ID:Meituan-Dianping,項目名稱:Robust,代碼行數:38,代碼來源:RobustAsmUtils.java

示例4: generateMethod

import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
 * 生成方法
 * @param cw
 * @param method
 * @param exceptions
 * @param interfaceClazz
 */
private static ClassWriter generateMethod(ClassWriter cw,java.lang.reflect.Method method,Class<Prepared> prepared){
	
	org.objectweb.asm.commons.Method m = new org.objectweb.asm.commons.Method(method.getName(), Type.getMethodDescriptor(method));
	GeneratorAdapter mv = new GeneratorAdapter(ACC_PUBLIC, m, null, null,cw);

	mv.visitLdcInsn(method.getName()); // excute的第1參數
	mv.visitLdcInsn(Type.getType(method).getDescriptor()); // excute的第2參數
	
	//  excute的第3參數(是可變參數)
	Parameter[] parameters = method.getParameters();
	mv = setIn(mv, parameters); 

	// excute的第4個參數
	mv.visitVarInsn(ALOAD, 0);
	
	// 調用Prepared中的excute方法
	// INVOKESTATIC
	mv.visitMethodInsn(INVOKESTATIC, Type.getType(prepared).getInternalName(), "excute", "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lorg/fastquery/core/Repository;)Ljava/lang/Object;", false);
	
	// 返回值處理
	String internalName  = Type.getInternalName(method.getReturnType());
	int sort = Type.getReturnType(method).getSort();
	if( sort == 0 ) { // 如果返回值是 Void
		mv.visitInsn(POP);
		mv.visitInsn(RETURN);
	} else if( (1 <= sort) && (sort <= 8)  ) { // 如果是基本類型 [1,8]
		Object[] objs = TypeUtil.getTypeInfo(Type.getReturnType(method).getDescriptor());
		String type = objs[0].toString();
		mv.visitTypeInsn(CHECKCAST, type);
		mv.visitMethodInsn(INVOKEVIRTUAL, type, objs[1].toString(), objs[2].toString(), false);
		// Integer.parseInt(objs[3].toString()) 比 Integer.valueOf(objs[3].toString()).intValue()更優.
		mv.visitInsn(Integer.parseInt(objs[3].toString()));
		
	} else { //sort==9 表述數組類型int[]或Integer[], srot=10表示包裝類型
		mv.visitTypeInsn(CHECKCAST, internalName);
		mv.visitInsn(ARETURN);
	}
	
	// mv.visitEnd()
	mv.endMethod();	
	return cw;
}
 
開發者ID:xixifeng,項目名稱:fastquery,代碼行數:50,代碼來源:AsmRepository.java


注:本文中的org.objectweb.asm.commons.GeneratorAdapter.visitLdcInsn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。