本文整理匯總了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();
}
示例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();
}
示例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()));
}
}
示例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;
}