Package org.mvel2.asm

Examples of org.mvel2.asm.ClassVisitor


        } catch (Exception e) {
        }
    }
   
    public void testIllegalFieldSignature() {
        ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
        cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
        try {
            cv.visitField(ACC_PUBLIC, "i", "I", "L;", null);
            fail();
        } catch (Exception e) {
        }
        try {
            cv.visitField(ACC_PUBLIC, "i", "I", "LC+", null);
            fail();
        } catch (Exception e) {
        }
        try {
            cv.visitField(ACC_PUBLIC, "i", "I", "LC;I", null);
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here


        } catch (Exception e) {
        }
    }

    public void testIllegalClassMemberVisitAfterEnd() {
        ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
        cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
        cv.visitEnd();
        try {
            cv.visitSource(null, null);
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalMethodSignature() {
        ClassVisitor cv = new CheckClassAdapter(new EmptyVisitor());
        cv.visit(V1_1, ACC_PUBLIC, "C", null, "java/lang/Object", null);
        try {
            cv.visitMethod(ACC_PUBLIC, "m", "()V", "<T::LI.J<*+LA;>;>()V^LA;X", null);
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

    }
   
    public void testIllegalDebugLabelUse() throws IOException {
        ClassReader cr = new ClassReader("java.lang.Object");
        ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS);
        ClassVisitor cv = new ClassAdapter(cw) {
            @Override
            public MethodVisitor visitMethod(
                int access,
                String name,
                String desc,
                String signature,
                String[] exceptions)
            {
                final MethodVisitor next = cv.visitMethod(access,
                        name,
                        desc,
                        signature,
                        exceptions);
                if (next == null) {
View Full Code Here

                skipTest();
                return;
            }
        }
        ClassWriter cw = new ClassWriter(0);
        ClassVisitor cv = new ClassAdapter(cw) {

            private String owner;

            @Override
            public void visit(
                final int version,
                final int access,
                final String name,
                final String signature,
                final String superName,
                final String[] interfaces)
            {
                owner = name;
                cv.visit(version,
                        access,
                        name,
                        signature,
                        superName,
                        interfaces);
            }

            @Override
            public MethodVisitor visitMethod(
                final int access,
                final String name,
                final String desc,
                final String signature,
                final String[] exceptions)
            {
                MethodVisitor mv = cv.visitMethod(access,
                        name,
                        desc,
                        signature,
                        exceptions);
                return new AnalyzerAdapter(owner, access, name, desc, mv);
View Full Code Here

    private final static TestClassLoader LOADER = new TestClassLoader();

    public void test() throws Exception {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        ClassVisitor cv = new StaticInitMerger("$clinit$", cw);
        cv.visit(V1_1, ACC_PUBLIC, "A", null, "java/lang/Object", null);
        cv.visitField(ACC_PUBLIC + ACC_STATIC, "counter", "I", null, null);
        for (int i = 0; i < 5; ++i) {
            MethodVisitor mv = cv.visitMethod(ACC_PUBLIC,
                    "<clinit>",
                    "()V",
                    null,
                    null);
            mv.visitFieldInsn(GETSTATIC, "A", "counter", "I");
            mv.visitInsn(ICONST_1);
            mv.visitInsn(IADD);
            mv.visitFieldInsn(PUTSTATIC, "A", "counter", "I");
            mv.visitInsn(RETURN);
            mv.visitMaxs(0, 0);
        }
        MethodVisitor mv = cv.visitMethod(ACC_PUBLIC,
                "<init>",
                "()V",
                null,
                null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        cv.visitEnd();

        Class<?> c = LOADER.defineClass("A", cw.toByteArray());
        assertEquals(c.getField("counter").getInt(c.newInstance()), 5);
    }
View Full Code Here

    @Override
    public void test() throws Exception {
        ClassReader cr = new ClassReader(is);
        ClassWriter cw = new ClassWriter(0);
        ClassVisitor cv = new TraceClassVisitor(cw,
                new PrintWriter(new CharArrayWriter()));
        cr.accept(cv, new Attribute[] { new Comment(), new CodeComment() }, 0);
        assertEquals(cr, new ClassReader(cw.toByteArray()));
    }
View Full Code Here

        // adapts the class on the fly
        try {
            ClassReader cr = new ClassReader(is);
            ClassWriter cw = new ClassWriter(0);
            ClassVisitor cv = new TraceFieldClassAdapter(cw);
            cr.accept(cv, 0);
            b = cw.toByteArray();
        } catch (Exception e) {
            throw new ClassNotFoundException(name, e);
        }
View Full Code Here

        final ClassFilter filter2) throws Exception
    {
        if (!Arrays.equals(cr1.b, cr2.b)) {
            StringWriter sw1 = new StringWriter();
            StringWriter sw2 = new StringWriter();
            ClassVisitor cv1 = new TraceClassVisitor(new PrintWriter(sw1));
            ClassVisitor cv2 = new TraceClassVisitor(new PrintWriter(sw2));
            if (filter1 != null) {
                filter1.setNext(cv1);
            }
            if (filter2 != null) {
                filter2.setNext(cv2);
View Full Code Here

    public void test() throws Exception {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        ClassReader cr = new ClassReader(is);
        ClassWriter cw = new ClassWriter(0);
        ClassVisitor cv = new JasminifierClassAdapter(pw, cw);
        cr.accept(cv,
                new Attribute[] { new Comment(), new CodeComment() },
                ClassReader.EXPAND_FRAMES);
        pw.close();
        String jasmin = sw.toString();
View Full Code Here

TOP

Related Classes of org.mvel2.asm.ClassVisitor

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.