Package org.ow2.asm

Examples of org.ow2.asm.ClassReader


        } catch (ClassFormatError cfe) {
            fail(cfe.getMessage());
        } catch (VerifyError ve) {
            String s = n.replace('.', '/') + ".class";
            InputStream is = getClass().getClassLoader().getResourceAsStream(s);
            ClassReader cr = new ClassReader(is);
            byte[] b = transformClass(cr.b);
            StringWriter sw1 = new StringWriter();
            StringWriter sw2 = new StringWriter();
            sw2.write(ve.toString() + "\n");
            ClassVisitor cv1 = new TraceClassVisitor(new PrintWriter(sw1));
            ClassVisitor cv2 = new TraceClassVisitor(new PrintWriter(sw2));
            cr.accept(cv1, 0);
            new ClassReader(b).accept(cv2, 0);
            String s1 = sw1.toString();
            String s2 = sw2.toString();
            assertEquals("different data", s1, s2);
        }
    }
View Full Code Here


    @Override
    public void test() throws Exception {
        if (n.startsWith("pkg.")) {
            return;
        }
        ClassReader cr = new ClassReader(is);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        CheckClassAdapter.verify(cr, false, pw);
        pw.close();
        String s = sw.toString();
View Full Code Here

        CheckClassAdapter.main(new String[] { s });
        CheckClassAdapter.main(new String[] { "output/test/cases/Interface.class" });
    }

    public void testVerifyValidClass() throws Exception {
        ClassReader cr = new ClassReader(getClass().getName());
        CheckClassAdapter.verify(cr, true, new PrintWriter(System.err));
    }
View Full Code Here

        mv.visitVarInsn(ISTORE, 30);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 31);
        mv.visitEnd();
        cw.visitEnd();
        ClassReader cr = new ClassReader(cw.toByteArray());
        CheckClassAdapter.verify(cr, true, new PrintWriter(System.err));
    }
View Full Code Here

        } catch (Exception e) {
        }
    }
   
    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) {
                    return next;
                }
                return new MethodAdapter(new CheckMethodAdapter(next)) {
                    private Label entryLabel = null;

                    @Override
                    public void visitLabel(Label label) {
                        if (entryLabel == null) {
                            entryLabel = label;
                        }
                        mv.visitLabel(label);
                    }

                    @Override
                    public void visitMaxs(int maxStack, int maxLocals) {
                        Label unwindhandler = new Label();
                        mv.visitLabel(unwindhandler);
                        mv.visitInsn(Opcodes.ATHROW); // rethrow
                        mv.visitTryCatchBlock(entryLabel,
                                unwindhandler,
                                unwindhandler,
                                null);
                        mv.visitMaxs(maxStack, maxLocals);
                    }
                };
            }
        };
        try {
            cr.accept(cv, ClassReader.EXPAND_FRAMES);
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

            System.err.println("Prints the ASM code to generate the given class.");
            System.err.println("Usage: GASMifierClassVisitor [-debug] "
                    + "<fully qualified class name or class file name>");
            System.exit(-1);
        }
        ClassReader cr;
        if (args[i].endsWith(".class")) {
            cr = new ClassReader(new FileInputStream(args[i]));
        } else {
            cr = new ClassReader(args[i]);
        }
        cr.accept(new GASMifierClassVisitor(new PrintWriter(System.out)),
                getDefaultAttributes(),
                ClassReader.EXPAND_FRAMES | flags);
    }
View Full Code Here

        return new AnalyzerAdapterTest().getSuite();
    }

    @Override
    public void test() throws Exception {
        ClassReader cr = new ClassReader(is);
        if (cr.readInt(4) != Opcodes.V1_6) {
            try {
                ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
                cr.accept(cw, 0);
                cr = new ClassReader(cw.toByteArray());
            } catch (Exception e) {
                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);
            }
        };
        cr.accept(cv, ClassReader.EXPAND_FRAMES);
    }
View Full Code Here

        return new JSRInlinerAdapterTest().getSuite();
    }

    @Override
    public void test() throws Exception {
        ClassReader cr = new ClassReader(is);
        ClassWriter cw = new ClassWriter(0);
        cr.accept(new ClassAdapter(cw) {
            @Override
            public MethodVisitor visitMethod(
                final int access,
                final String name,
                final String desc,
View Full Code Here

        return new SimpleVerifierTest().getSuite();
    }

    @Override
    public void test() throws Exception {
        ClassReader cr = new ClassReader(is);
        ClassNode cn = new ClassNode();
        cr.accept(cn, 0);
        List<MethodNode> methods = cn.methods;
        for (int i = 0; i < methods.size(); ++i) {
            MethodNode method = methods.get(i);
            Analyzer<?> a = new Analyzer<BasicValue>(new SimpleVerifier());
            a.analyze(cn.name, method);
View Full Code Here

        public Class<?> loadClass(final String name) throws ClassNotFoundException
        {
            if (name.startsWith(prefix)) {
                try {
                    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
                    ClassReader cr = new ClassReader(getClass().getResourceAsStream("/"
                            + name.replace('.', '/') + ".class"));
                    cr.accept(new AdviceClassAdapter(cw),
                            ClassReader.EXPAND_FRAMES);
                    byte[] bytecode = cw.toByteArray();
                    return super.defineClass(name, bytecode, 0, bytecode.length);
                } catch (IOException ex) {
                    throw new ClassNotFoundException("Load error: "
View Full Code Here

TOP

Related Classes of org.ow2.asm.ClassReader

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.