Package org.ow2.asm

Examples of org.ow2.asm.MethodVisitor


        } catch (Exception e) {
        }
    }

    public void testIllegalFieldInsnReferenceDesc2() {
        MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
        mv.visitCode();
        try {
            mv.visitFieldInsn(GETFIELD, "C", "i", "L-;");
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here


        generate(dir, "pkg/Wide.class", dump());
    }

    public byte[] dump() {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        MethodVisitor mv;

        cw.visit(V1_2, ACC_PUBLIC, "pkg/Wide", null, "java/lang/Object", null);

        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
        for (int i = 0; i < 256; ++i) {
            mv.visitLdcInsn(Integer.toString(i)); // wide form
            mv.visitInsn(POP);
        }
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();

        mv = cw.visitMethod(ACC_PUBLIC, "wideLocals", "(I)I", null, null);
        mv.visitCode();
        Label l0 = new Label();
        Label l1 = new Label();
        mv.visitJumpInsn(GOTO, l1); // will give GOTO_W

        mv.visitLabel(l0);
        mv.visitIincInsn(300, 1); // covers 'update maxlocals' in MethodWriter
        mv.visitVarInsn(ILOAD, 300); // will give wide form
        mv.visitJumpInsn(IFEQ, l1); // will give long forward jump

        // many NOPs will be introduced here by the method resizing test

        mv.visitVarInsn(ILOAD, 300); // will give wide form
        mv.visitInsn(IRETURN);

        mv.visitLabel(l1);
        for (int i = 1; i < 300; ++i) {
            mv.visitVarInsn(ILOAD, i);
            if (i <= 5) {
                mv.visitInsn(ICONST_0 + i);
            } else if (i <= Byte.MAX_VALUE) {
                mv.visitIntInsn(BIPUSH, i);
            } else {
                mv.visitIntInsn(SIPUSH, i);
            }
            mv.visitInsn(IADD);
            mv.visitVarInsn(ISTORE, i + 1);
        }
        mv.visitInsn(ICONST_0);
        mv.visitJumpInsn(IFEQ, l0); // will give long backward jump
        mv.visitJumpInsn(GOTO, l0); // will give long backward goto

        mv.visitMaxs(0, 0);
        mv.visitEnd();

        cw.visitEnd();

        return cw.toByteArray();
    }
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalMethodInsnNullName() {
        MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
        mv.visitCode();
        try {
            mv.visitMethodInsn(INVOKEVIRTUAL, "C", null, "()V");
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalMethodInsnName() {
        MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
        mv.visitCode();
        try {
            mv.visitMethodInsn(INVOKEVIRTUAL, "C", "-", "()V");
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalMethodInsnName2() {
        MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
        mv.visitCode();
        try {
            mv.visitMethodInsn(INVOKEVIRTUAL, "C", "a-", "()V");
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalMethodInsnNullDesc() {
        MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
        mv.visitCode();
        try {
            mv.visitMethodInsn(INVOKEVIRTUAL, "C", "m", null);
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalMethodInsnDesc() {
        MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
        mv.visitCode();
        try {
            mv.visitMethodInsn(INVOKEVIRTUAL, "C", "m", "I");
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalMethodInsnParameterDesc() {
        MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
        mv.visitCode();
        try {
            mv.visitMethodInsn(INVOKEVIRTUAL, "C", "m", "(V)V");
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalMethodInsnReturnDesc() {
        MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
        mv.visitCode();
        try {
            mv.visitMethodInsn(INVOKEVIRTUAL, "C", "m", "()VV");
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalLdcInsnOperand() {
        MethodVisitor mv = new CheckMethodAdapter(new EmptyVisitor());
        mv.visitCode();
        try {
            mv.visitLdcInsn(new Object());
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

TOP

Related Classes of org.ow2.asm.MethodVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.