Example usage for org.objectweb.asm.commons LocalVariablesSorter visitInsn

List of usage examples for org.objectweb.asm.commons LocalVariablesSorter visitInsn

Introduction

In this page you can find the example usage for org.objectweb.asm.commons LocalVariablesSorter visitInsn.

Prototype

public void visitInsn(final int opcode) 

Source Link

Document

Visits a zero operand instruction.

Usage

From source file:rubah.bytecode.transformers.AddTraverseMethod.java

License:Open Source License

private void generateTraverseMethod() {
    LocalVariablesSorter mv = new LocalVariablesSorter(TRAVERSE_METHOD_ACC_FLAGS, TRAVERSE_METHOD_DESC,
            this.visitMethod(this.getTraverseMethodAccess(), this.getTraverseMethodName(), TRAVERSE_METHOD_DESC,
                    null, null));//from   ww  w.  ja  va  2s  . co  m
    mv.visitCode();

    if (isAllowed(this.thisClass.getFqn())) {
        this.generateTraverseMethodPreamble(mv);

        if (!this.fields.isEmpty()) {
            for (Pair<String, String> field : this.fields) {
                this.generateFieldAccess(mv, field);
            }
        }
    }
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

From source file:rubah.bytecode.transformers.AddTraverseMethod.java

License:Open Source License

protected void generateFieldAccess(LocalVariablesSorter mv, Pair<String, String> field) {
    Type fieldType = Type.getType(field.getValue1());

    if (!isAllowed(fieldType.getClassName())) {
        return;//  w w  w.  j  a  v  a2 s. c  o m
    }

    this.getFieldOwner(mv);
    mv.visitInsn(DUP);

    mv.visitFieldInsn(GETFIELD, this.thisClass.getASMType().getInternalName(), field.getValue0(),
            field.getValue1());
    mv.visitMethodInsn(INVOKESTATIC, REGISTER_METHOD_OWNER_NAME, REGISTER_METHOD_NAME,
            REGISTER_METHOD_SIMPLE_DESC, false);
    if (this.version != null) {
        mv.visitTypeInsn(CHECKCAST, this.version.eraseUpdatableType(this.namespace.getClass(fieldType))
                .getASMType().getInternalName());
    } else {
        mv.visitTypeInsn(CHECKCAST, fieldType.getInternalName());
    }
    mv.visitFieldInsn(PUTFIELD, this.thisClass.getASMType().getInternalName(), field.getValue0(),
            field.getValue1());
}