Java 类org.objectweb.asm.util.ASMifierClassVisitor 实例源码

项目:eclectic    文件:IdcClassLoader.java   
protected byte[] transform(final String pName, final InputStream pClassStream) throws IOException {
    System.err.println("Transforming " + pName);


    final byte[] oldClass = IOUtils.toByteArray(pClassStream);
    final byte[] newClass = transformer.transform(oldClass);

    // CheckClassAdapter.verify(new ClassReader(newClass), true);

    new ClassReader(oldClass).accept(
            new ASMifierClassVisitor(
                    new PrintWriter(
                            new FileOutputStream(
                                    transformer.getClass().getSimpleName() + pName + ".old"))), 0);

    new ClassReader(newClass).accept(
            new ASMifierClassVisitor(
                    new PrintWriter(
                            new FileOutputStream(
                                    transformer.getClass().getSimpleName() + pName + ".new"))), 0);

    return newClass;
}
项目:eclectic    文件:ClassTransformerClassLoader.java   
protected byte[] transform(final String pName, final InputStream pClassStream) throws IOException {
    final byte[] oldClass = IOUtils.toByteArray(pClassStream);
    final byte[] newClass = transformer.transform(oldClass);

    // CheckClassAdapter.verify(new ClassReader(newClass), true);

    new ClassReader(oldClass).accept(
            new ASMifierClassVisitor(
                    new PrintWriter(
                            new FileOutputStream(
                                    transformer.getClass().getSimpleName() + pName + ".old"))), 0);

    new ClassReader(newClass).accept(
            new ASMifierClassVisitor(
                    new PrintWriter(
                            new FileOutputStream(
                                    transformer.getClass().getSimpleName() + pName + ".new"))), 0);

    return newClass;
}
项目:lodil    文件:ClassNodeTest.java   
@Test
@Ignore
public void test() throws IOException {
    for (final Class clazz : new Class[] { HandTypesArrayList.class, HandTypesAllocation.class, HandTypesListElement.class,
            HandTypesValueImpl.class }) {
        // for (Class clazz : new Class[]{HandTypesArrayList.class}) {
        final ClassReader cr = new ClassReader(clazz.getName());
        final StringWriter sw = new StringWriter();
        final ASMifierClassVisitor cv = new ASMifierClassVisitor(new PrintWriter(sw));
        cr.accept(cv, 0);
        final String text = sw.toString();
        System.out.println(text.replaceAll("\"com/weibo/lodil/mmap/hand/HandTypes", "name + \"")
                .replaceAll("Lcom/weibo/lodil/mmap/hand/HandTypes", "L\" + name + \"")
                .replaceAll("\"com/weibo/lodil/mmap/HandTypes\"", "name")
                .replaceAll("Lcom/weibo/lodil/mmap/HandTypes;", "L\" + name + \";")
                .replaceAll("\"com/weibo/lodil/mmap/", "collections + \"")
                .replaceAll("Lcom/weibo/lodil/mmap/", "L\" + collections + \""));
    }
}
项目:annotation-tools    文件:ASMStackMapTableAttributeTest.java   
public void test() throws Exception {
    String n = "org.objectweb.asm.attrs.StackMapTableSample";
    InputStream is = StackMapTableAttributeTest.class.getResourceAsStream(StackMapTableAttributeTest.TEST_CLASS);
    ClassReader cr = new ClassReader(is);

    StringWriter sw = new StringWriter();
    ASMifierClassVisitor cv = new ASMifierClassVisitor(new PrintWriter(sw));
    cr.accept(cv, AbstractVisitor.getDefaultAttributes(), false);

    String generated = sw.toString();

    byte[] generatorClassData;
    try {
        generatorClassData = ASMifierTest.COMPILER.compile(n, generated);
        System.err.println(generated);
    } catch (Exception ex) {
        System.err.println(generated);
        System.err.println("------------------");
        throw ex;
    }

    Class c = ASMifierTest.LOADER.defineClass("asm." + n + "Dump",
            generatorClassData);
    Method m = c.getMethod("dump", new Class[0]);
    byte[] b = (byte[]) m.invoke(null, new Object[0]);

    assertEquals(cr, new ClassReader(b));
}