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

项目:jooby    文件:BytecodeRouteParser.java   
private ClassNode loadClass(String name) {
  return Try.apply(() -> {
    String cname = name.replace("/", ".");
    ClassNode node = cache.get(cname);
    if (node == null) {
      String rname = cname.replace(".", "/") + ".class";
      try (InputStream in = loader.getResourceAsStream(rname)) {
        if (in == null) {
          throw new FileNotFoundException(rname + " using " + loader);
        }
        ClassReader reader = new ClassReader(ByteStreams.toByteArray(in));
        node = new ClassNode();
        reader.accept(node, 0);
        cache.put(cname, node);
        if (log.isDebugEnabled()) {
          log.info("Source: {}; Class: {}", node.sourceFile, node.name);
          reader.accept(
              new TraceClassVisitor(null, new ASMifier(), new PrintWriter(writer(log, name))),
              0);
        }
      }
    }
    return node;
  }).get();
}
项目:salta    文件:RecipeCompiler.java   
public Class<?> loadClass(ClassCompilationContext ctx) {
    // generate bytecode
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    ctx.getClazz().accept(cw);

    // load class
    Class<?> cls;
    byte[] bb = cw.toByteArray();
    String className = Type.getObjectType(ctx.getClazz().name).getClassName();

    // try {
    // Files.write(bb, new File("target/compiledRecipes/" + ctx.clazz.name
    // + ".class"));
    // } catch (IOException e2) {
    // throw new SaltaException("Error while writing generated class", e2);
    // }

    try {
        cls = getLoader().defineClass(className, bb);
        ctx.initFields(cls);
    } catch (Throwable e) {
        System.out.println("Error while loading compiled recipe class");
        ClassReader cr = new ClassReader(bb);
        cr.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(System.out)), 0);
        CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));

        throw new SaltaException("Error while loading compiled recipe", e);
    }

    // return result
    return cls;
}
项目:Cojac    文件:FloatReplaceClassVisitor.java   
private Printer newPrinter(final String s) {
    Printer printer=new ASMifier(Opcodes.ASM5, "mv", 0) {  // or Textifier(ASM5)
        @Override public void visitMethodEnd() {
            System.out.println("======================== "+s+" ==================");
            PrintWriter p=new PrintWriter(System.out);
            print(p);
            p.flush(); // don't forget that!
        }
    };
    return printer;
}
项目:jeff    文件:ASMifierTest.java   
public static void main(String[] args) throws Exception {
    ImmutableList<Class<?>> classes = ImmutableList.of(
            HelloWorld.class
    );
    for (Class<?> aClass : classes) {
        System.out.println("----------------------------------------------------------------------------------------------------------------------------------");
        ASMifier.main(new String[] {
                aClass.getCanonicalName()
        });
        System.out.println("----------------------------------------------------------------------------------------------------------------------------------");
    }
}
项目:uranus    文件:GenClassTestCase.java   
@Test
public void printClass(){
    try {
        ASMifier.main(new String[]{AccountVO1Wrapper.class.getName()}); 
    } catch (Exception e) {
        Assert.fail("asmifier", e);
    }
}
项目:uranus    文件:EntityWrapperTestCase.java   
@Test
public void gen(){//得到wrapper的样本
    try {
        ASMifier.main(new String[]{AccountVO.class.getName()});
    } catch (Exception e) {
        Assert.fail("gen class", e);
    }
}
项目:groovy    文件:JO.java   
public static void main(String[] args) throws Exception {
        ASMifier.main(new String[]{"target/classes/groovy/swing/SwingBuilder.class"});
//        ASMifierClassVisitor.main(new String[]{"target/classes/org/codehaus/groovy/tools/shell/util/HelpFormatter.class"});
//        ASMifierClassVisitor.main(new String[]{"target/classes/org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite.class"});
//        ASMifierClassVisitor.main(new String[]{"target/test-classes/spectralnorm.class"});
//        ASMifierClassVisitor.main(new String[]{"target/test-classes/groovy/bugs/CustomMetaClassTest.class"});
    }
项目:glowroot    文件:Weaver.java   
private static String toASM(byte[] transformedBytes) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    ClassReader cr = new ClassReader(transformedBytes);
    TraceClassVisitor tcv = new TraceClassVisitor(null, new ASMifier(), pw);
    cr.accept(tcv, ClassReader.EXPAND_FRAMES);
    pw.close();
    return sw.toString();
}
项目:pinpoint    文件:ASMBytecodeDisassembler.java   
public String dumpASM(byte[] bytecode) {
    if (bytecode == null) {
        throw new NullPointerException("bytecode must not be null");
    }

    return writeBytecode(bytecode, new ASMifier());
}
项目:asm-legacy-svn-clone    文件:GASMifier.java   
@Override
public ASMifier visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    buf.setLength(0);
    buf.append("{\n");
    buf.append("mg = new TestGeneratorAdapter(");
    buf.append(access);
    buf.append(", ");
    buf.append(getMethod(name, desc));
    buf.append(", ");
    if (signature == null) {
        buf.append("null");
    } else {
        buf.append('"').append(signature).append('"');
    }
    buf.append(", ");
    if (exceptions != null && exceptions.length > 0) {
        buf.append("new Type[] {");
        for (int i = 0; i < exceptions.length; ++i) {
            buf.append(i == 0 ? " " : ", ");
            buf.append(getType(exceptions[i]));
        }
        buf.append(" }");
    } else {
        buf.append("null");
    }
    buf.append(", cw);\n");
    text.add(buf.toString());
    GASMifier av = new GASMifier(access, desc);
    text.add(av.getText());
    text.add("}\n");
    return av;
}
项目:asm-legacy-svn-clone    文件:GASMifier.java   
@Override
public Printer visitLocalVariableAnnotation(int typeRef, TypePath typePath,
        Label[] start, Label[] end, int[] index, String desc,
        boolean visible) {
    buf.setLength(0);
    buf.append("{\n").append("av0 = ").append(name)
            .append(".getNext().visitLocalVariableAnnotation(");
    buf.append(typeRef);
    buf.append(", TypePath.fromString(\"").append(typePath).append("\"), ");
    buf.append("new Label[] {");
    for (int i = 0; i < start.length; ++i) {
        buf.append(i == 0 ? " " : ", ");
        appendLabel(start[i]);
    }
    buf.append(" }, new Label[] {");
    for (int i = 0; i < end.length; ++i) {
        buf.append(i == 0 ? " " : ", ");
        appendLabel(end[i]);
    }
    buf.append(" }, new int[] {");
    for (int i = 0; i < index.length; ++i) {
        String idx = index[i] < firstLocal ? new Integer(index[i])
                .toString() : "local" + locals.get(new Integer(index[i]));
        buf.append(i == 0 ? " " : ", ").append(idx);
    }
    buf.append(" }, ");
    appendConstant(desc);
    buf.append(", ").append(visible).append(");\n");
    text.add(buf.toString());
    ASMifier a = createASMifier("av", 0);
    text.add(a.getText());
    text.add("}\n");
    return a;
}
项目:ow2-asm    文件:GASMifier.java   
@Override
public ASMifier visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    buf.setLength(0);
    buf.append("{\n");
    buf.append("mg = new TestGeneratorAdapter(");
    buf.append(access);
    buf.append(", ");
    buf.append(getMethod(name, desc));
    buf.append(", ");
    if (signature == null) {
        buf.append("null");
    } else {
        buf.append('"').append(signature).append('"');
    }
    buf.append(", ");
    if (exceptions != null && exceptions.length > 0) {
        buf.append("new Type[] {");
        for (int i = 0; i < exceptions.length; ++i) {
            buf.append(i == 0 ? " " : ", ");
            buf.append(getType(exceptions[i]));
        }
        buf.append(" }");
    } else {
        buf.append("null");
    }
    buf.append(", cw);\n");
    text.add(buf.toString());
    GASMifier av = new GASMifier(access, desc);
    text.add(av.getText());
    text.add("}\n");
    return av;
}
项目:ow2-asm    文件:GASMifier.java   
@Override
public Printer visitLocalVariableAnnotation(int typeRef, TypePath typePath,
        Label[] start, Label[] end, int[] index, String desc,
        boolean visible) {
    buf.setLength(0);
    buf.append("{\n").append("av0 = ").append(name)
            .append(".getNext().visitLocalVariableAnnotation(");
    buf.append(typeRef);
    buf.append(", TypePath.fromString(\"").append(typePath).append("\"), ");
    buf.append("new Label[] {");
    for (int i = 0; i < start.length; ++i) {
        buf.append(i == 0 ? " " : ", ");
        appendLabel(start[i]);
    }
    buf.append(" }, new Label[] {");
    for (int i = 0; i < end.length; ++i) {
        buf.append(i == 0 ? " " : ", ");
        appendLabel(end[i]);
    }
    buf.append(" }, new int[] {");
    for (int i = 0; i < index.length; ++i) {
        String idx = index[i] < firstLocal ? new Integer(index[i])
                .toString() : "local" + locals.get(new Integer(index[i]));
        buf.append(i == 0 ? " " : ", ").append(idx);
    }
    buf.append(" }, ");
    appendConstant(desc);
    buf.append(", ").append(visible).append(");\n");
    text.add(buf.toString());
    ASMifier a = createASMifier("av", 0);
    text.add(a.getText());
    text.add("}\n");
    return a;
}
项目:objectweb-asm-4.0    文件:GASMifier.java   
@Override
public ASMifier visitMethod(
    final int access,
    final String name,
    final String desc,
    final String signature,
    final String[] exceptions)
{
    buf.setLength(0);
    buf.append("{\n");
    buf.append("mg = new GeneratorAdapter(");
    buf.append(access);
    buf.append(", ");
    buf.append(getMethod(name, desc));
    buf.append(", ");
    if (signature == null) {
        buf.append("null");
    } else {
        buf.append('"').append(signature).append('"');
    }
    buf.append(", ");
    if (exceptions != null && exceptions.length > 0) {
        buf.append("new Type[] {");
        for (int i = 0; i < exceptions.length; ++i) {
            buf.append(i == 0 ? " " : ", ");
            buf.append(getType(exceptions[i]));
        }
        buf.append(" }");
    } else {
        buf.append("null");
    }
    buf.append(", cw);\n");
    text.add(buf.toString());
    GASMifier av = new GASMifier(access, desc);
    text.add(av.getText());
    text.add("}\n");
    return av;
}
项目:dlcheck    文件:TestClass.java   
public static void main(String[] args) throws Exception {
    ASMifier.main(new String[]{"com.devexperts.dlcheck.tests.base.Test$B"});
}
项目:dlcheck    文件:Test.java   
public static void main(String[] args) throws Exception {
//        Runnable r = new MyClassLoader().load().newInstance();
//        r.run();
        ASMifier.main(new String[]{Test.class.getCanonicalName()});
    }
项目:fastquery    文件:TestASMifier.java   
public static void main(String[] args) throws Exception {
    // "Hi.class" 对应的字节码通过ASM工具怎样一步一步生成出来呢? 通过调用ASMifier.main, 可以得到通过ASM工具生成bytes的详细源码.
    // 解释太绕了, 运行一下便知
    ASMifier.main(new String[]{ "/mywork/myosgi/osgi_workspace/fastquery/target/test-classes/org/fastquery/bean/StudentDBServiceProxyImpl.class"} );
}
项目:polygene-java    文件:ASMTest.java   
@Test
public void generateASM()
    throws Exception
{
    ASMifier.main( new String[]{ SomeMixin_Stubx.class.getName() } );
}
项目:QuickTheories    文件:CoverageTransformerTest.java   
protected void printClass(final byte[] bs) {
  final ClassReader reader = new ClassReader(bs);
  reader.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(
      System.out)), ClassReader.EXPAND_FRAMES);
}
项目:pitest    文件:MutatorTestBase.java   
protected void printMutant(final Mutant mutant) {    
   final ClassReader reader = new ClassReader(mutant.getBytes());
   reader.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(
       System.out)), ClassReader.EXPAND_FRAMES);
}
项目:pitest    文件:CoverageTransformerTest.java   
protected void printClass(final byte[] bs) {
  final ClassReader reader = new ClassReader(bs);
  reader.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(
      System.out)), ClassReader.EXPAND_FRAMES);
}
项目:asm-legacy-svn-clone    文件:GASMifier.java   
@Override
protected ASMifier createASMifier(final String name, final int id) {
    return new GASMifier(name, id);
}
项目:jooby    文件:Insn.java   
@Override public String toString() {
  Printer printer = new ASMifier();
  TraceMethodVisitor visitor = new TraceMethodVisitor(printer);
  node.accept(visitor);
  return printer.getText().toString();
}
项目:ow2-asm    文件:GASMifier.java   
@Override
protected ASMifier createASMifier(final String name, final int id) {
    return new GASMifier(name, id);
}
项目:objectweb-asm-4.0    文件:GASMifier.java   
@Override
protected ASMifier createASMifier(final String name, final int id) {
    return new GASMifier(name, id);
}
项目:beetl2.0    文件:ASMSource.java   
/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    ASMifier.main(new String[] { "org.beetl.performance.lab.asm.PrivateTestGet" });

}
项目:beetl2.0    文件:ASMSource.java   
/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    ASMifier.main(new String[] { "com.beetl.performance.lab.asm.field.UserIdFiledAccess" });

}
项目:beetl2.0    文件:ASMSource.java   
/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    ASMifier.main(new String[] { "org.beetl.performance.lab.asm.PrivateTestGet" });

}
项目:beetl2.0    文件:ASMSource.java   
/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    ASMifier.main(new String[] { "com.beetl.performance.lab.asm.field.UserIdFiledAccess" });

}