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


Java MethodVisitor.visitEnd方法代碼示例

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


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

示例1: addGetProperty

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void addGetProperty() {
    MethodVisitor methodVisitor = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, "getProperty", RETURN_OBJECT_FROM_STRING, null, null);
    methodVisitor.visitCode();

    // this.getMetaClass()
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, "getMetaClass", RETURN_META_CLASS, false);

    // getProperty(this, name)
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
    methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, META_CLASS_TYPE.getInternalName(), "getProperty", RETURN_OBJECT_FROM_OBJECT_STRING, true);

    // return
    methodVisitor.visitInsn(Opcodes.ARETURN);
    methodVisitor.visitMaxs(3, 2);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:19,代碼來源:MixInLegacyTypesClassLoader.java

示例2: addInvokeMethod

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void addInvokeMethod() {
    MethodVisitor methodVisitor = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, "invokeMethod", RETURN_OBJECT_FROM_STRING_OBJECT, null, null);
    methodVisitor.visitCode();

    // this.getMetaClass()
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, "getMetaClass", RETURN_META_CLASS, false);

    // invokeMethod(this, name, args)
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 2);
    methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, META_CLASS_TYPE.getInternalName(), "invokeMethod",  RETURN_OBJECT_FROM_OBJECT_STRING_OBJECT, true);

    // return
    methodVisitor.visitInsn(Opcodes.ARETURN);
    methodVisitor.visitMaxs(4, 3);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:20,代碼來源:MixInLegacyTypesClassLoader.java

示例3: applyServiceInjectionToSetter

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
public void applyServiceInjectionToSetter(PropertyMetaData property, Method setter) throws Exception {
    // GENERATE public void <setter>(<type> value) { <field> == value }
    String methodDescriptor = Type.getMethodDescriptor(setter);
    Type serviceType = Type.getType(property.getType());
    String propFieldName = propFieldName(property);

    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, setter.getName(), methodDescriptor, signature(setter), EMPTY_STRINGS);
    methodVisitor.visitCode();

    // this.field = value
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, generatedType.getInternalName(), propFieldName, serviceType.getDescriptor());

    // return
    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:20,代碼來源:AsmBackedClassGenerator.java

示例4: addSetMethod

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
public void addSetMethod(PropertyMetaData property, Method setter) throws Exception {
    Type paramType = Type.getType(setter.getParameterTypes()[0]);
    Type returnType = Type.getType(setter.getReturnType());
    String setterDescriptor = Type.getMethodDescriptor(returnType, paramType);

    // GENERATE public void <propName>(<type> v) { <setter>(v) }
    String setMethodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, paramType);
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, property.getName(), setMethodDescriptor, null, EMPTY_STRINGS);
    methodVisitor.visitCode();

    // GENERATE <setter>(v)

    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitVarInsn(paramType.getOpcode(Opcodes.ILOAD), 1);

    methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, generatedType.getInternalName(), setter.getName(), setterDescriptor, false);

    // END

    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:24,代碼來源:AsmBackedClassGenerator.java

示例5: generateClass

import org.objectweb.asm.MethodVisitor; //導入方法依賴的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

示例6: addGetMetaClass

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void addGetMetaClass() {
    Label lookup = new Label();

    MethodVisitor methodVisitor = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, "getMetaClass", RETURN_META_CLASS, null, null);
    methodVisitor.visitCode();

    // if (this.metaClass != null) { return this.metaClass; }
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitFieldInsn(Opcodes.GETFIELD, className, META_CLASS_FIELD, META_CLASS_TYPE.getDescriptor());
    methodVisitor.visitInsn(Opcodes.DUP);
    methodVisitor.visitJumpInsn(Opcodes.IFNULL, lookup);
    methodVisitor.visitInsn(Opcodes.ARETURN);

    methodVisitor.visitLabel(lookup);
    methodVisitor.visitFrame(Opcodes.F_NEW, 1, new Object[]{className}, 1, new Object[]{META_CLASS_TYPE.getInternalName()});
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); // for storing to field

    // GroovySystem.getMetaClassRegistry()
    methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, GROOVY_SYSTEM_TYPE.getInternalName(), "getMetaClassRegistry", RETURN_META_CLASS_REGISTRY, false);

    // this.getClass()
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, OBJECT_TYPE.getInternalName(), "getClass", RETURN_CLASS, false);

    // getMetaClass(..)
    methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, META_CLASS_REGISTRY_TYPE.getInternalName(), "getMetaClass", RETURN_META_CLASS_FROM_CLASS, true);

    // this.metaClass = <value>
    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, className, META_CLASS_FIELD, META_CLASS_TYPE.getDescriptor());

    // return this.metaClass
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitFieldInsn(Opcodes.GETFIELD, className, META_CLASS_FIELD, META_CLASS_TYPE.getDescriptor());

    methodVisitor.visitInsn(Opcodes.ARETURN);
    methodVisitor.visitMaxs(4, 1);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:39,代碼來源:MixInLegacyTypesClassLoader.java

示例7: visitMethod

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
    if ((access & ACC_ABSTRACT) == 0) {
        mv.visitCode();
        mv.visitMethodInsn(
            INVOKESTATIC, internalClassName, UOE_METHOD, "()Ljava/lang/UnsupportedOperationException;", false);
        mv.visitInsn(ATHROW);
        mv.visitMaxs(1, 0);
        mv.visitEnd();
    }
    return mv;
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:14,代碼來源:MethodStubbingApiMemberAdapter.java

示例8: insertConstructor

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
static private void insertConstructor(ClassWriter cw, String superclassNameInternal) {
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
	mv.visitCode();
	mv.visitVarInsn(ALOAD, 0);
	mv.visitMethodInsn(INVOKESPECIAL, superclassNameInternal, "<init>", "()V");
	mv.visitInsn(RETURN);
	mv.visitMaxs(1, 1);
	mv.visitEnd();
}
 
開發者ID:HankXV,項目名稱:Limitart,代碼行數:11,代碼來源:ConstructorAccess.java

示例9: 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();
}
 
開發者ID:primeval-io,項目名稱:primeval-reflex,代碼行數:16,代碼來源:MethodArgumentsGenerator.java

示例10: apply

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
public void apply(MethodVisitor mv) {
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESTATIC, "com/lhh/lkdb/LKDBModelManager", "insertToDB", "(Lcom/lhh/lkdb/ILKDBModel;)Z", false);
    mv.visitInsn(IRETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}
 
開發者ID:MeetYouDevs,項目名稱:LKDBHelper-ORM-Android,代碼行數:9,代碼來源:InsertToDBApply.java

示例11: addSetter

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void addSetter(Method method, MethodCodeBody body) throws Exception {
    String methodDescriptor = Type.getMethodDescriptor(method);
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, method.getName(), methodDescriptor, null, EMPTY_STRINGS);
    methodVisitor.visitCode();
    body.add(methodVisitor);
    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:10,代碼來源:AsmBackedClassGenerator.java

示例12: 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();
}
 
開發者ID:primeval-io,項目名稱:primeval-reflex,代碼行數:52,代碼來源:MethodArgumentssUpdaterGenerator.java

示例13: insertNewInstance

import org.objectweb.asm.MethodVisitor; //導入方法依賴的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

示例14: applyConventionMappingToSetter

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
public void applyConventionMappingToSetter(PropertyMetaData property, Method setter) throws Exception {
    // GENERATE public <return-type> <setter>(<type> v) { <return-type> v = super.<setter>(v); __<prop>__ = true; return v; }

    Type paramType = Type.getType(setter.getParameterTypes()[0]);
    Type returnType = Type.getType(setter.getReturnType());
    String setterDescriptor = Type.getMethodDescriptor(returnType, paramType);
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, setter.getName(), setterDescriptor, null, EMPTY_STRINGS);
    methodVisitor.visitCode();

    // GENERATE super.<setter>(v)

    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitVarInsn(paramType.getOpcode(Opcodes.ILOAD), 1);

    methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), setter.getName(), setterDescriptor, false);

    // END

    // GENERATE __<prop>__ = true

    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitLdcInsn(true);
    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, generatedType.getInternalName(), propFieldName(property), Type.BOOLEAN_TYPE.getDescriptor());

    // END

    methodVisitor.visitInsn(returnType.getOpcode(Opcodes.IRETURN));
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:31,代碼來源:AsmBackedClassGenerator.java

示例15: createConstructor

import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
private void createConstructor(ClassWriter cw, String classDesc) {
    Label start = new Label();
    Label end = new Label();

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    mv.visitLabel(start);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, BytecodeGenerator.OBJECT.getInternalName(), "<init>", "()V", false);
    mv.visitInsn(RETURN);
    mv.visitLabel(end);
    mv.visitLocalVariable("this", classDesc, null, start, end, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}
 
開發者ID:Guichaguri,項目名稱:FastMustache,代碼行數:16,代碼來源:MustacheCompiler.java


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