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


Java ClassWriter.visitMethod方法代码示例

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


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

示例1: generateClass

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
private static byte[] generateClass(Class<? extends TileEntity> baseClass, String className, String contentId)
{
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, className, null, Type.getInternalName(baseClass), null);

    // Constructor
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(contentId);
    mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(baseClass), "<init>", "(Ljava/lang/String;)V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(2, 1);
    mv.visitEnd();

    return cw.toByteArray();
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:17,代码来源:TileEntityRegistry.java

示例2: createMainMethod

import org.objectweb.asm.ClassWriter; //导入方法依赖的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();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:JavaInstallationProbe.java

示例3: generateUpdateMethod

import org.objectweb.asm.ClassWriter; //导入方法依赖的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();
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:26,代码来源:MethodArgumentssUpdaterGenerator.java

示例4: createConstructor

import org.objectweb.asm.ClassWriter; //导入方法依赖的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();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:16,代码来源:JavaInstallationProbe.java

示例5: visitBlockStructured

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
private static void visitBlockStructured(ClassWriter cw, boolean normalReturnError, boolean tooMany) {
    String name = (tooMany ? "tooMany" : "tooFew") + "Exits" + (normalReturnError ? "" : "Exceptional");
    // Generate too many or too few exits down the either the normal or exceptional return
    // paths
    int exceptionalExitCount = normalReturnError ? 1 : (tooMany ? 2 : 0);
    int normalExitCount = normalReturnError ? (tooMany ? 2 : 0) : 1;
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, name, "(Ljava/lang/Object;Ljava/lang/Object;)Z", null, null);
    mv.visitCode();
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, null);
    Label l3 = new Label();
    mv.visitTryCatchBlock(l2, l3, l2, null);
    Label l4 = new Label();
    Label l5 = new Label();
    Label l6 = new Label();
    mv.visitTryCatchBlock(l4, l5, l6, null);
    Label l7 = new Label();
    mv.visitTryCatchBlock(l2, l7, l6, null);
    Label l8 = new Label();
    mv.visitLabel(l8);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 3);
    mv.visitInsn(MONITORENTER);
    mv.visitLabel(l4);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 4);
    mv.visitInsn(MONITORENTER);
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false);
    mv.visitVarInsn(ALOAD, 4);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l1);
    for (int i = 0; i < normalExitCount; i++) {
        mv.visitVarInsn(ALOAD, 3);
        mv.visitInsn(MONITOREXIT);
    }
    mv.visitLabel(l5);
    mv.visitInsn(IRETURN);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_FULL, 5, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object",
                    "java/lang/Object"}, 1, new Object[]{"java/lang/Throwable"});
    mv.visitVarInsn(ALOAD, 4);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l3);
    mv.visitInsn(ATHROW);
    mv.visitLabel(l6);
    mv.visitFrame(Opcodes.F_FULL, 4, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object"}, 1,
                    new Object[]{"java/lang/Throwable"});
    for (int i = 0; i < exceptionalExitCount; i++) {
        mv.visitVarInsn(ALOAD, 3);
        mv.visitInsn(MONITOREXIT);
    }
    mv.visitLabel(l7);
    mv.visitInsn(ATHROW);
    Label l9 = new Label();
    mv.visitLabel(l9);
    mv.visitMaxs(2, 5);
    mv.visitEnd();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:67,代码来源:UnbalancedMonitorsTest.java

示例6: insertConstructor

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
static private void insertConstructor(ClassWriter cw) {
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
	mv.visitCode();
	mv.visitVarInsn(ALOAD, 0);
	mv.visitMethodInsn(INVOKESPECIAL, ReflectASMConst.PACKAGE_NAME + "FieldAccess", "<init>", "()V");
	mv.visitInsn(RETURN);
	mv.visitMaxs(1, 1);
	mv.visitEnd();
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:11,代码来源:FieldAccess.java

示例7: insertNewInstance

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
static void insertNewInstance(ClassWriter cw, String classNameInternal) {
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "newInstance", "()Ljava/lang/Object;", null, null);
	mv.visitCode();
	mv.visitTypeInsn(NEW, classNameInternal);
	mv.visitInsn(DUP);
	mv.visitMethodInsn(INVOKESPECIAL, classNameInternal, "<init>", "()V");
	mv.visitInsn(ARETURN);
	mv.visitMaxs(2, 1);
	mv.visitEnd();
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:12,代码来源:ConstructorAccess.java

示例8: generateParametersGetter

import org.objectweb.asm.ClassWriter; //导入方法依赖的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();
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:16,代码来源:MethodArgumentsGenerator.java

示例9: testClassLoading

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
@Test
public void testClassLoading() throws Exception {
    SimpleClassLoader simpleClassLoader = new SimpleClassLoader(ClassLoader.getSystemClassLoader());

    String className = getClass().getPackage().getName()+".GeneratedTestClass";
    String classNameInternal = className.replaceAll("\\.", "/");

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, classNameInternal, null, Type.getInternalName(Object.class), null);
    {
        FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "test", Type.getDescriptor(String.class), null, "hey");
        fv.visitEnd();
    }
    {
        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
        cw.visitEnd();
    }
    cw.visitEnd();

    /* Test class loading */
    Class<?> generated = ClassLoaderTools.defineClass(simpleClassLoader, className, cw.toByteArray());
    Assertions.assertNotNull(generated, "Class didn't load!");
    Assertions.assertTrue(Reflect.getClass(className, simpleClassLoader).isPresent(),
            "Class isn't present in classloader!");
    Assertions.assertFalse(Reflect.getClass(className).isPresent()
            , "Class is present in system class loader!");

    /* Test field */
    ClassWrapper<?> c = Reflect.construct(Reflect.wrapClass(generated));
    Optional<FieldWrapper<String>> testFieldOptional = c.getField("test", String.class);
    Assertions.assertTrue(testFieldOptional.isPresent(), "Test field is not present!");
    Assertions.assertEquals("hey", testFieldOptional.get().read(), "Test field content didn't match!");
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:39,代码来源:ClassLoadingTester.java

示例10: visit

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
@Override
public Object visit(ASTStreamSignature node, Object data) throws CompileException {

  LangUnitNode stream_hdr = node.getChildren(0);
  Debug.assertion(stream_hdr.isNodeId(JJTSTREAMHEADER),
      "first child should be Stream Type, but(" + stream_hdr.getNodeName() + ")");

  switch (stream_hdr.getStreamForm()) {
  case LangUnitNode.STREAMFORM_CLASS: {
    TContextClass class_context = (TContextClass) this.getTopContext();
    Debug.assertion(class_context != null, "top context should not be null");
    Debug.assertion(class_context.isForm(AbsType.FORM_CLASS), "top context should be class");

    String class_name = class_context.getName();

    String super_class_name = null;
    AbsClassType super_class = class_context.getSuperClass();

    if (super_class != null) {
      super_class_name = ((AbsType) super_class).getName();
      Debug.assertion(super_class_name != null, "Super Class Name should not be invalid");
    }

    String[] interfaces = check_interface_impl_and_get(class_context);

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    class_context.setClassWriter(cw);

    LOG.info("Creating Public Class...({}) super({})", class_name, super_class_name);

    //// Writing Byte Code
    cw.visit(Compiler.java_version, Opcodes.ACC_PUBLIC, class_name, null, super_class_name, interfaces);

    if (class_context.isGenDfltConstructor()) {
      // if it does not have any constructor, add a dummy constructor
      // default constructor
      MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
      mv.visitCode();

      // super class default constructor call
      if (super_class != null) {
        LOG.info("ALOAD 0");
        LOG.info("INVOKESPECIAL " + super_class_name + " <init> ()V");

        mv.visitVarInsn(Opcodes.ALOAD, 0); // this
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, super_class_name, "<init>", "()V", false);
      }

      if (Debug.enable_compile_debug_print) {
        // LOG.info("GETSTATIC java/lang/System.out");
        // LOG.info("LDC "+class_name+" was instantiated");
        // LOG.info("INVOKEVIRTUAL java/io/PrintStream.println");
        mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        mv.visitLdcInsn(class_name + " was instantiated");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
      }
      mv.visitInsn(Opcodes.RETURN);
      mv.visitMaxs(0, 0);
      mv.visitEnd();
      //// end Byte Code
    }

  }
    break;

  default:
    // do nothing for other stream form ...
  }

  return null;
}
 
开发者ID:Samsung,项目名称:MeziLang,代码行数:72,代码来源:ASTCompileVisitor.java

示例11: makeClazz

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
private static byte[] makeClazz() {
    // Code generated the class below using asm.
    String clazzName = DeoptimizeOnExceptionTest.class.getName().replace('.', '/');
    final ClassWriter w = new ClassWriter(0);
    w.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC,
                    "t/TestJSR", null, "java/lang/Object",
                    new String[]{"java/lang/Runnable"});
    MethodVisitor mv = w.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[]{});
    mv.visitCode();
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(10, 10);
    mv.visitEnd();

    mv = w.visitMethod(Opcodes.ACC_PUBLIC, "run", "()V", null, null);
    mv.visitCode();
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false);
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.JSR, l1);
    mv.visitInsn(Opcodes.RETURN);

    mv.visitLabel(l1);
    mv.visitVarInsn(Opcodes.ASTORE, 1);

    Label lElse = new Label();
    Label lEnd = new Label();
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false);
    mv.visitInsn(Opcodes.POP2);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false);
    mv.visitInsn(Opcodes.DUP);
    mv.visitJumpInsn(Opcodes.IFNULL, lElse);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodA", "()V", false);
    mv.visitJumpInsn(Opcodes.GOTO, lEnd);
    mv.visitLabel(lElse);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodB", "()V", false);
    mv.visitLabel(lEnd);

    mv.visitVarInsn(Opcodes.RET, 1);
    mv.visitMaxs(10, 10);
    mv.visitEnd();
    return w.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:DeoptimizeOnExceptionTest.java

示例12: createWrapper

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
public Class<?> createWrapper(Method callback)
{
    if (cache.containsKey(callback))
    {
        return cache.get(callback);
    }

    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;

    boolean isStatic = Modifier.isStatic(callback.getModifiers());
    String name = getUniqueName(callback);
    String desc = name.replace('.',  '/');
    String instType = Type.getInternalName(callback.getDeclaringClass());
    String eventType = Type.getInternalName(callback.getParameterTypes()[0]);

    /*
    System.out.println("Name:     " + name);
    System.out.println("Desc:     " + desc);
    System.out.println("InstType: " + instType);
    System.out.println("Callback: " + callback.getName() + Type.getMethodDescriptor(callback));
    System.out.println("Event:    " + eventType);
    */

    cw.visit(V1_6, ACC_PUBLIC | ACC_SUPER, desc, null, "java/lang/Object", new String[]{ HANDLER_DESC });

    cw.visitSource(".dynamic", null);
    {
        if (!isStatic)
            cw.visitField(ACC_PUBLIC, "instance", "Ljava/lang/Object;", null, null).visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", isStatic ? "()V" : "(Ljava/lang/Object;)V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        if (!isStatic)
        {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitVarInsn(ALOAD, 1);
            mv.visitFieldInsn(PUTFIELD, desc, "instance", "Ljava/lang/Object;");
        }
        mv.visitInsn(RETURN);
        mv.visitMaxs(2, 2);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "invoke", HANDLER_FUNC_DESC, null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        if (!isStatic)
        {
            mv.visitFieldInsn(GETFIELD, desc, "instance", "Ljava/lang/Object;");
            mv.visitTypeInsn(CHECKCAST, instType);
        }
        mv.visitVarInsn(ALOAD, 1);
        mv.visitTypeInsn(CHECKCAST, eventType);
        mv.visitMethodInsn(isStatic ? INVOKESTATIC : INVOKEVIRTUAL, instType, callback.getName(), Type.getMethodDescriptor(callback), false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(2, 2);
        mv.visitEnd();
    }
    cw.visitEnd();
    Class<?> ret = LOADER.define(name, cw.toByteArray());
    cache.put(callback, ret);
    return ret;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:68,代码来源:ASMEventHandler.java

示例13: generateArgumentGetters

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
private static void generateArgumentGetters(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        Parameter[] parameters) {
    MethodVisitor mv;
    {
        mv = cw.visitMethod(ACC_PUBLIC, "objectArg", "(Ljava/lang/String;)Ljava/lang/Object;",
                "<T:Ljava/lang/Object;>(Ljava/lang/String;)TT;", null);
        generateArgGetterCode(Object.class, mv, selfClassInternalName, selfClassDescriptor, parameters);
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "intArg", "(Ljava/lang/String;)I", null, null);
        generateArgGetterCode(int.class, mv, selfClassInternalName, selfClassDescriptor, parameters);
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "shortArg", "(Ljava/lang/String;)S", null, null);
        generateArgGetterCode(short.class, mv, selfClassInternalName, selfClassDescriptor, parameters);
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "longArg", "(Ljava/lang/String;)J", null, null);
        generateArgGetterCode(long.class, mv, selfClassInternalName, selfClassDescriptor, parameters);
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "byteArg", "(Ljava/lang/String;)B", null, null);
        generateArgGetterCode(byte.class, mv, selfClassInternalName, selfClassDescriptor, parameters);
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "booleanArg", "(Ljava/lang/String;)Z", null, null);
        generateArgGetterCode(boolean.class, mv, selfClassInternalName, selfClassDescriptor, parameters);
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "floatArg", "(Ljava/lang/String;)F", null, null);
        generateArgGetterCode(float.class, mv, selfClassInternalName, selfClassDescriptor, parameters);
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "doubleArg", "(Ljava/lang/String;)D", null, null);
        generateArgGetterCode(double.class, mv, selfClassInternalName, selfClassDescriptor, parameters);
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "charArg", "(Ljava/lang/String;)C", null, null);
        generateArgGetterCode(char.class, mv, selfClassInternalName, selfClassDescriptor, parameters);
    }
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:42,代码来源:MethodArgumentssUpdaterGenerator.java

示例14: insertGetString

import org.objectweb.asm.ClassWriter; //导入方法依赖的package包/类
static private void insertGetString(ClassWriter cw, String classNameInternal, ArrayList<Field> fields) {
	int maxStack = 6;
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getString", "(Ljava/lang/Object;I)Ljava/lang/String;", null,
			null);
	mv.visitCode();
	mv.visitVarInsn(ILOAD, 2);

	if (!fields.isEmpty()) {
		maxStack--;
		Label[] labels = new Label[fields.size()];
		Label labelForInvalidTypes = new Label();
		boolean hasAnyBadTypeLabel = false;
		for (int i = 0, n = labels.length; i < n; i++) {
			if (fields.get(i).getType().equals(String.class))
				labels[i] = new Label();
			else {
				labels[i] = labelForInvalidTypes;
				hasAnyBadTypeLabel = true;
			}
		}
		Label defaultLabel = new Label();
		mv.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels);

		for (int i = 0, n = labels.length; i < n; i++) {
			if (!labels[i].equals(labelForInvalidTypes)) {
				mv.visitLabel(labels[i]);
				mv.visitFrame(F_SAME, 0, null, 0, null);
				mv.visitVarInsn(ALOAD, 1);
				mv.visitTypeInsn(CHECKCAST, classNameInternal);
				mv.visitFieldInsn(GETFIELD, classNameInternal, fields.get(i).getName(), "Ljava/lang/String;");
				mv.visitInsn(ARETURN);
			}
		}
		// Rest of fields: different type
		if (hasAnyBadTypeLabel) {
			mv.visitLabel(labelForInvalidTypes);
			mv.visitFrame(F_SAME, 0, null, 0, null);
			insertThrowExceptionForFieldType(mv, "String");
		}
		// Default: field not found
		mv.visitLabel(defaultLabel);
		mv.visitFrame(F_SAME, 0, null, 0, null);
	}
	insertThrowExceptionForFieldNotFound(mv);
	mv.visitMaxs(maxStack, 3);
	mv.visitEnd();
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:48,代码来源:FieldAccess.java

示例15: findClass

import org.objectweb.asm.ClassWriter; //导入方法依赖的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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:LargeConstantSectionTest.java


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