/**
  * This will return a series of bytecode instructions which can be used to compare one method with
  * another. debug info like local var declarations and line numbers are ignored, so the focus is
  * on the content.
  */
 public static List getMethodBytecode(final String methodName, final byte[] bytes) {
   final Tracer visit = new Tracer(methodName);
   final ClassReader classReader = new ClassReader(bytes);
   classReader.accept(visit, ClassReader.SKIP_DEBUG);
   final TraceMethodVisitor trace = visit.getTrace();
   return trace.getText();
 }
Exemple #2
0
  public static java.util.List getMethodBytecode(
      Class cls, String ruleClassName, String packageName, String methodName, String resource) {
    org.drools.core.util.asm.MethodComparator.Tracer visit =
        new org.drools.core.util.asm.MethodComparator.Tracer(methodName);

    java.io.InputStream is = cls.getClassLoader().getResourceAsStream(resource);

    java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
    try {
      byte[] data = new byte[1024];
      int byteCount;
      while ((byteCount = is.read(data, 0, 1024)) > -1) {
        bos.write(data, 0, byteCount);
      }
    } catch (java.io.IOException e) {
      throw new RuntimeDroolsException(
          "Unable getResourceAsStream for Class '" + ruleClassName + "' ");
    }

    org.mvel2.asm.ClassReader classReader = new org.mvel2.asm.ClassReader(bos.toByteArray());
    classReader.accept(visit, org.mvel2.asm.ClassReader.SKIP_DEBUG);
    org.mvel2.asm.util.TraceMethodVisitor trace = visit.getTrace();
    return trace.getText();
  }