本文整理汇总了Java中org.objectweb.asm.MethodVisitor.visitLocalVariable方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitLocalVariable方法的具体用法?Java MethodVisitor.visitLocalVariable怎么用?Java MethodVisitor.visitLocalVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.MethodVisitor
的用法示例。
在下文中一共展示了MethodVisitor.visitLocalVariable方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createObjectRender
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void createObjectRender(ClassWriter cw, String className, String classDesc, Type data) {
Label start = new Label();
Label end = new Label();
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, "render",
Type.getMethodDescriptor(BytecodeGenerator.STRING, BytecodeGenerator.OBJECT), null, null);
mv.visitCode();
mv.visitLabel(start);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitTypeInsn(CHECKCAST, data.getInternalName());
mv.visitMethodInsn(INVOKEVIRTUAL, className, "render", Type.getMethodDescriptor(BytecodeGenerator.STRING, data), false);
mv.visitInsn(ARETURN);
mv.visitLabel(end);
mv.visitLocalVariable("this", classDesc, null, start, end, 0);
//mv.visitLocalVariable("obj", data.getDescriptor(), null, start, end, 1);
mv.visitMaxs(2, 2);
mv.visitEnd();
}
示例2: createMainMethod
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void createMainMethod(ClassWriter cw) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
for (SysProp type : SysProp.values()) {
if (type != SysProp.Z_ERROR) {
dumpProperty(mv, type.sysProp);
}
}
mv.visitInsn(RETURN);
Label l3 = new Label();
mv.visitLabel(l3);
mv.visitLocalVariable("args", "[Ljava/lang/String;", null, l0, l3, 0);
mv.visitMaxs(3, 1);
mv.visitEnd();
}
示例3: generateUpdateMethod
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateUpdateMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
String argsClassInternalName,
String constDesc, Parameter[] parameters) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, "update", "()Lio/primeval/reflex/arguments/Arguments;", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitTypeInsn(NEW, argsClassInternalName);
mv.visitInsn(DUP);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, selfClassInternalName, parameter.getName(), Type.getDescriptor(parameter.getType()));
}
mv.visitMethodInsn(INVOKESPECIAL, argsClassInternalName, "<init>", constDesc, false);
mv.visitInsn(ARETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
示例4: generateUpdaterMethod
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateUpdaterMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
String updaterClassInternalName,
String constDesc, Parameter[] parameters) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, "updater", "()Lio/primeval/reflex/arguments/ArgumentsUpdater;", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitTypeInsn(NEW, updaterClassInternalName);
mv.visitInsn(DUP);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, selfClassInternalName, parameter.getName(), Type.getDescriptor(parameter.getType()));
}
mv.visitMethodInsn(INVOKESPECIAL, updaterClassInternalName, "<init>", constDesc, false);
mv.visitInsn(ARETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
示例5: createConstructor
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void createConstructor(ClassWriter cw) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
mv.visitInsn(RETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "LJavaProbe;", null, l0, l1, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
示例6: addBooleanGetGetter
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void addBooleanGetGetter(String booleanField) {
MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, "get" + StringUtils.capitalize(booleanField), "()Z", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, className, booleanField, "Z");
mv.visitInsn(Opcodes.IRETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
示例7: generateToStringMethod
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateToStringMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
Parameter[] parameters) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
mv.visitInsn(DUP);
mv.visitLdcInsn(Type.getType(selfClassDescriptor));
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getSimpleName", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
mv.visitLdcInsn(" [");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
for (int i = 0; i < parameters.length; i++) {
Parameter param = parameters[i];
mv.visitLdcInsn(param.getName() + "=");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
false);
mv.visitVarInsn(ALOAD, 0); // this
mv.visitFieldInsn(GETFIELD, selfClassInternalName, param.getName(), Type.getDescriptor(param.getType()));
Class<?> paramType = param.getType();
if (paramType.isPrimitive()) {
// special case with StringBuilder, no specific method we default to append(int)
if (paramType == short.class || paramType == byte.class) {
paramType = int.class;
}
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
Type.getMethodDescriptor(Type.getType(StringBuilder.class), Type.getType(paramType)), false);
} else {
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
"(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false);
}
if (i + 1 < parameters.length) {
mv.visitLdcInsn(", ");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
false);
}
}
mv.visitLdcInsn("]");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
mv.visitInsn(ARETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
示例8: generateParametersGetter
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateParametersGetter(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, "parameters", "()Ljava/util/List;", "()Ljava/util/List<Ljava/lang/reflect/Parameter;>;", null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
mv.visitInsn(ARETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
示例9: visitDefaultConstructor
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public static void visitDefaultConstructor(ClassWriter cw, String classTypeDescriptor) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
mv.visitInsn(RETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", classTypeDescriptor, null, l0, l1, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
示例10: generateHashCodeMethod
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateHashCodeMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
Parameter[] parameters) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, "hashCode", "()I", null, null);
mv.visitCode();
// int result = 1;
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitInsn(ICONST_1);
mv.visitVarInsn(ISTORE, 1);
for (Parameter param : parameters) {
Class<?> type = param.getType();
mv.visitIntInsn(BIPUSH, 31);
mv.visitVarInsn(ILOAD, 1);
mv.visitInsn(IMUL);
mv.visitVarInsn(ALOAD, 0);
Type typeType = Type.getType(type);
mv.visitFieldInsn(GETFIELD, selfClassInternalName, param.getName(), typeType.getDescriptor());
if (type.isPrimitive()) {
Class<?> boxed = BytecodeGenUtils.getBoxed(type);
mv.visitMethodInsn(INVOKESTATIC, Type.getInternalName(boxed), "hashCode",
Type.getMethodDescriptor(Type.INT_TYPE, typeType), false);
} else {
mv.visitMethodInsn(INVOKESTATIC, "java/util/Objects", "hashCode", "(Ljava/lang/Object;)I", false);
}
mv.visitInsn(IADD);
mv.visitVarInsn(ISTORE, 1);
}
mv.visitVarInsn(ILOAD, 1);
mv.visitInsn(IRETURN);
Label l7 = new Label();
mv.visitLabel(l7);
mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l7, 0);
mv.visitLocalVariable("result", "I", null, l0, l7, 1);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
示例11: findClass
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.equals(NAME)) {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
cw.visit(52, ACC_PUBLIC + ACC_SUPER, NAME, null, "java/lang/Object", null);
mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "run", "(I)J", null, null);
mv.visitCode();
Label begin = new Label();
mv.visitLabel(begin);
mv.visitVarInsn(ILOAD, 0);
Label[] labels = new Label[numberBlocks];
int[] keys = new int[numberBlocks];
for (int i = 0; i < labels.length; i++) {
labels[i] = new Label();
keys[i] = i;
}
Label defaultLabel = new Label();
mv.visitLookupSwitchInsn(defaultLabel, keys, labels);
for (int i = 0; i < labels.length; i++) {
mv.visitLabel(labels[i]);
mv.visitFrame(Opcodes.F_NEW, 1, new Object[]{Opcodes.INTEGER}, 0, new Object[]{});
mv.visitLdcInsn(new Long(LARGE_CONSTANT + i));
mv.visitInsn(LRETURN);
}
mv.visitLabel(defaultLabel);
mv.visitFrame(Opcodes.F_NEW, 1, new Object[]{Opcodes.INTEGER}, 0, new Object[]{});
mv.visitLdcInsn(new Long(3L));
mv.visitInsn(LRETURN);
Label end = new Label();
mv.visitLabel(end);
mv.visitLocalVariable("a", "I", null, begin, end, 0);
mv.visitMaxs(2, 1);
mv.visitEnd();
byte[] bytes = cw.toByteArray();
return defineClass(name, bytes, 0, bytes.length);
} else {
return super.findClass(name);
}
}
示例12: accept
import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
* Makes the given visitor visit this local variable declaration.
*
* @param mv
* a method visitor.
*/
public void accept(final MethodVisitor mv) {
mv.visitLocalVariable(name, desc, signature, start.getLabel(),
end.getLabel(), index);
}