Example usage for org.objectweb.asm MethodVisitor visitEnd

List of usage examples for org.objectweb.asm MethodVisitor visitEnd

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitEnd.

Prototype

public void visitEnd() 

Source Link

Document

Visits the end of the method.

Usage

From source file:com.google.gwtorm.protobuf.CodecGen.java

License:Apache License

private void implementDecode() throws OrmException {
    final Type retType = object;
    final MethodVisitor mv = cw.visitMethod(ACC_PROTECTED, "decode",
            Type.getMethodDescriptor(retType, new Type[] { codedInputStream }), null, new String[] {});
    mv.visitCode();/*from   w  w w. j  a  v a 2 s  .c  o m*/
    final DecodeCGS cgs = new DecodeCGS(mv);

    cgs.setEntityType(pojoType);

    mv.visitTypeInsn(NEW, pojoType.getInternalName());
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL, pojoType.getInternalName(), "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
    mv.visitVarInsn(ASTORE, cgs.objVar);

    final int tagVar = cgs.newLocal();
    decodeMessage(myFields, mv, cgs);

    cgs.pushEntity();
    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.server.SchemaConstructorGen.java

License:Apache License

private void implementConstructor() {
    final Type ft = Type.getType(schemaArg.getClass());
    final String consName = "<init>";
    final String consDesc = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { ft });
    final MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, consName, consDesc, null, null);
    mv.visitCode();/*from  w ww . j  a  v  a  2  s.  c o  m*/

    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(Object.class), consName,
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));

    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitFieldInsn(PUTFIELD, implTypeName, CTX, ft.getDescriptor());

    mv.visitInsn(RETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.server.SchemaConstructorGen.java

License:Apache License

private void implementNewInstance() {
    final Type ft = Type.getType(schemaArg.getClass());
    final String typeName = Type.getType(schemaImpl).getInternalName();
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, "open",
            Type.getMethodDescriptor(Type.getType(Schema.class), new Type[] {}), null, null);
    mv.visitCode();/*from  w  ww. j a va2  s .com*/

    Constructor<?> c = schemaImpl.getDeclaredConstructors()[0];
    Type argType = Type.getType(c.getParameterTypes()[0]);

    mv.visitTypeInsn(NEW, typeName);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, implTypeName, CTX, ft.getDescriptor());
    mv.visitMethodInsn(INVOKESPECIAL, typeName, "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { argType }));
    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.server.SchemaGen.java

License:Apache License

private void implementConstructor() {
    final String consName = "<init>";
    final Type superType = Type.getType(schemaSuperClass);
    final Type dbType = Type.getType(databaseClass);

    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, consName,
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { dbType }), null, null);
    mv.visitCode();/*from  www .j  a va  2s  .  c  o  m*/

    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, superType.getInternalName(), consName, Type.getMethodDescriptor(
            Type.VOID_TYPE,
            new Type[] { Type.getType(schemaSuperClass.getDeclaredConstructors()[0].getParameterTypes()[0]) }));

    for (final RelationGen info : relations) {
        mv.visitVarInsn(ALOAD, 0);
        mv.visitTypeInsn(NEW, info.accessType.getInternalName());
        mv.visitInsn(DUP);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, info.accessType.getInternalName(), consName,
                Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { superType }));
        mv.visitFieldInsn(PUTFIELD, implTypeName, info.getAccessInstanceFieldName(),
                info.accessType.getDescriptor());
    }

    mv.visitInsn(RETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.google.gwtorm.server.SchemaGen.java

License:Apache License

private void implementSequenceMethods() {
    for (final SequenceModel seq : schema.getSequences()) {
        final Type retType = Type.getType(seq.getResultType());
        final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, seq.getMethodName(),
                Type.getMethodDescriptor(retType, new Type[] {}), null,
                new String[] { Type.getType(OrmException.class).getInternalName() });
        mv.visitCode();//from w ww . j  a v  a 2 s . c  o  m

        mv.visitVarInsn(ALOAD, 0);
        mv.visitLdcInsn(seq.getSequenceName());
        mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(schemaSuperClass), "nextLong",
                Type.getMethodDescriptor(Type.getType(Long.TYPE), new Type[] { Type.getType(String.class) }));
        if (retType.getSize() == 1) {
            mv.visitInsn(L2I);
            mv.visitInsn(IRETURN);
        } else {
            mv.visitInsn(LRETURN);
        }
        mv.visitMaxs(-1, -1);
        mv.visitEnd();
    }
}

From source file:com.google.gwtorm.server.SchemaGen.java

License:Apache License

private void implementAllRelationsMethod() {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_FINAL, "allRelations",
            Type.getMethodDescriptor(Type.getType(Access[].class), new Type[] {}), null, null);
    mv.visitCode();//from w w  w . ja  v a2 s.  com

    final int r = 1;
    CodeGenSupport cgs = new CodeGenSupport(mv);
    cgs.push(relations.size());
    mv.visitTypeInsn(ANEWARRAY, Type.getType(Access.class).getInternalName());
    mv.visitVarInsn(ASTORE, r);

    int index = 0;
    for (RelationGen info : relations) {
        mv.visitVarInsn(ALOAD, r);
        cgs.push(index++);

        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, getImplTypeName(), info.model.getMethodName(), info.getDescriptor());

        mv.visitInsn(AASTORE);
    }

    mv.visitVarInsn(ALOAD, r);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}

From source file:com.googlecode.ddom.weaver.asm.MethodVisitorTee.java

License:Apache License

public void visitEnd() {
    for (MethodVisitor visitor : visitors) {
        visitor.visitEnd();
    }
}

From source file:com.googlecode.ddom.weaver.compound.CompoundClassGenerator.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, name, desc, signature, exceptions);
    if (mv != null) {
        Type[] argumentTypes = Type.getArgumentTypes(desc);
        mv.visitCode();//w ww  .  java  2  s .  c o  m
        Label l0 = new Label();
        mv.visitLabel(l0);
        for (int i = 0; i < componentClasses.length; i++) {
            String componentClass = Util.classNameToInternalName(componentClasses[i]);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, className, "c" + i, "L" + componentClass + ";");
            for (int j = 0; j < argumentTypes.length; j++) {
                mv.visitVarInsn(argumentTypes[j].getOpcode(Opcodes.ILOAD), j + 1);
            }
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, ifaceName, name, desc);
        }
        mv.visitInsn(Opcodes.RETURN);
        Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0);
        mv.visitMaxs(argumentTypes.length + 1, argumentTypes.length + 1);
        mv.visitEnd();
    }
    return null;
}

From source file:com.googlecode.ddom.weaver.compound.CompoundClassGenerator.java

License:Apache License

@Override
public void visitEnd() {
    for (int i = 0; i < componentClasses.length; i++) {
        String componentClass = Util.classNameToInternalName(componentClasses[i]);
        FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE, "c" + i, "L" + componentClass + ";", null, null);
        if (fv != null) {
            fv.visitEnd();/*from w ww  .j  a  va 2  s  .  co m*/
        }
    }
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
    if (mv != null) {
        mv.visitCode();
        Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
        for (int i = 0; i < componentClasses.length; i++) {
            String componentClass = Util.classNameToInternalName(componentClasses[i]);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitTypeInsn(Opcodes.NEW, componentClass);
            mv.visitInsn(Opcodes.DUP);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, componentClass, "<init>", "()V");
            mv.visitFieldInsn(Opcodes.PUTFIELD, className, "c" + i, "L" + componentClass + ";");
        }
        mv.visitInsn(Opcodes.RETURN);
        Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0);
        mv.visitMaxs(3, 1);
        mv.visitEnd();
    }
    cv.visitEnd();
}

From source file:com.googlecode.ddom.weaver.ext.ModelExtensionClass.java

License:Apache License

public void accept(ClassVisitor classVisitor) {
    ImplementationInfo implementationInfo = info.getImplementation().get(ImplementationInfo.class);
    String name = Util.classNameToInternalName(info.getClassName());
    String superName = Util.classNameToInternalName(info.getSuperClassName());
    classVisitor.visit(Opcodes.V1_5,//from   w w w.  ja  va 2s .  com
            info.isAbstract() ? Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT : Opcodes.ACC_PUBLIC, name, null,
            superName, new String[] {
                    Util.classNameToInternalName(info.getExtensionInterface().getClassInfo().getName()) });
    for (ConstructorInfo constructor : implementationInfo.getConstructors()) {
        MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", constructor.getDescriptor(),
                constructor.getSignature(), constructor.getExceptions());
        if (mv != null) {
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            Type[] argumentTypes = constructor.getArgumentTypes();
            for (int i = 0; i < argumentTypes.length; i++) {
                mv.visitVarInsn(argumentTypes[i].getOpcode(Opcodes.ILOAD), i + 1);
            }
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", constructor.getDescriptor());
            mv.visitInsn(Opcodes.RETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", "L" + name + ";", null, l0, l1, 0);
            for (int i = 0; i < argumentTypes.length; i++) {
                mv.visitLocalVariable("arg" + i, argumentTypes[i].getDescriptor(), null, l0, l1, i + 1);
            }
            mv.visitMaxs(argumentTypes.length + 1, argumentTypes.length + 1);
            mv.visitEnd();
        }
    }
    classVisitor.visitEnd();
}