Java 类org.mockito.asm.ClassReader 实例源码

项目:mockito-cglib    文件:ClassNameReader.java   
public static String[] getClassInfo(ClassReader r) {
    final List array = new ArrayList();
    try {
        r.accept(new ClassAdapter(null) {
            public void visit(int version,
                              int access,
                              String name,
                              String signature,
                              String superName,
                              String[] interfaces) {
                array.add( name.replace('/', '.') );
                if(superName != null){
                  array.add( superName.replace('/', '.') );
                }
                for(int i = 0; i < interfaces.length; i++  ){
                   array.add( interfaces[i].replace('/', '.') );
                }

                throw EARLY_EXIT;
            }
        }, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
    } catch (EarlyExitException e) { }

    return (String[])array.toArray( new String[]{} );
}
项目:astor    文件:ClassNameReader.java   
public static String[] getClassInfo(ClassReader r) {
    final List array = new ArrayList();
    try {
        r.accept(new ClassAdapter(null) {
            public void visit(int version,
                              int access,
                              String name,
                              String signature,
                              String superName,
                              String[] interfaces) {
                array.add( name.replace('/', '.') );
                if(superName != null){
                  array.add( superName.replace('/', '.') );
                }
                for(int i = 0; i < interfaces.length; i++  ){
                   array.add( interfaces[i].replace('/', '.') );
                }

                throw EARLY_EXIT;
            }
        }, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
    } catch (EarlyExitException e) { }

    return (String[])array.toArray( new String[]{} );
}
项目:astor    文件:ClassNameReader.java   
public static String[] getClassInfo(ClassReader r) {
    final List array = new ArrayList();
    try {
        r.accept(new ClassAdapter(null) {
            public void visit(int version,
                              int access,
                              String name,
                              String signature,
                              String superName,
                              String[] interfaces) {
                array.add( name.replace('/', '.') );
                if(superName != null){
                  array.add( superName.replace('/', '.') );
                }
                for(int i = 0; i < interfaces.length; i++  ){
                   array.add( interfaces[i].replace('/', '.') );
                }

                throw EARLY_EXIT;
            }
        }, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
    } catch (EarlyExitException e) { }

    return (String[])array.toArray( new String[]{} );
}
项目:mockito-cglib    文件:ClassReaderGenerator.java   
public ClassReaderGenerator(ClassReader r, int flags) {
    this(r, null, flags);
}
项目:mockito-cglib    文件:ClassReaderGenerator.java   
public ClassReaderGenerator(ClassReader r, Attribute[] attrs, int flags) {
    this.r = r;
    this.attrs = (attrs != null) ? attrs : new Attribute[0];
    this.flags = flags;
}
项目:mockito-cglib    文件:AbstractClassLoader.java   
protected ClassGenerator getGenerator(ClassReader r) {
    return new ClassReaderGenerator(r, attributes(), getFlags());
}
项目:mockito-cglib    文件:DebuggingClassWriter.java   
public byte[] toByteArray() {

return (byte[]) java.security.AccessController.doPrivileged(
  new java.security.PrivilegedAction() {
      public Object run() {


          byte[] b = DebuggingClassWriter.super.toByteArray();
          if (debugLocation != null) {
              String dirs = className.replace('.', File.separatorChar);
              try {
                  new File(debugLocation + File.separatorChar + dirs).getParentFile().mkdirs();

                  File file = new File(new File(debugLocation), dirs + ".class");
                  OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
                  try {
                      out.write(b);
                  } finally {
                      out.close();
                  }

                  if (traceEnabled) {
                      file = new File(new File(debugLocation), dirs + ".asm");
                      out = new BufferedOutputStream(new FileOutputStream(file));
                      try {
                          ClassReader cr = new ClassReader(b);
                          PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
                          TraceClassVisitor tcv = new TraceClassVisitor(null, pw);
                          cr.accept(tcv, 0);
                          pw.flush();
                      } finally {
                          out.close();
                      }
                  }
              } catch (IOException e) {
                  throw new CodeGenerationException(e);
              }
          }
          return b;
       }  
      });

  }
项目:mockito-cglib    文件:CheckClassAdapter.java   
/**
 * Checks a given class
 * 
 * @param cr a <code>ClassReader</code> that contains bytecode for the
 *        analysis.
 * @param dump true if bytecode should be printed out not only when errors
 *        are found.
 * @param pw write where results going to be printed
 */
public static void verify(
    final ClassReader cr,
    final boolean dump,
    final PrintWriter pw)
{
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn), ClassReader.SKIP_DEBUG);

    Type syperType = cn.superName == null
            ? null
            : Type.getObjectType(cn.superName);
    List methods = cn.methods;
    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = (MethodNode) methods.get(i);
        Analyzer a = new Analyzer(new SimpleVerifier(Type.getObjectType(cn.name),
                syperType,
                false));
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        Frame[] frames = a.getFrames();

        TraceMethodVisitor mv = new TraceMethodVisitor();

        pw.println(method.name + method.desc);
        for (int j = 0; j < method.instructions.size(); ++j) {
            method.instructions.get(j).accept(mv);

            StringBuffer s = new StringBuffer();
            Frame f = frames[j];
            if (f == null) {
                s.append('?');
            } else {
                for (int k = 0; k < f.getLocals(); ++k) {
                    s.append(getShortName(f.getLocal(k).toString()))
                            .append(' ');
                }
                s.append(" : ");
                for (int k = 0; k < f.getStackSize(); ++k) {
                    s.append(getShortName(f.getStack(k).toString()))
                            .append(' ');
                }
            }
            while (s.length() < method.maxStack + method.maxLocals + 1) {
                s.append(' ');
            }
            pw.print(Integer.toString(j + 100000).substring(1));
            pw.print(" " + s + " : " + mv.buf); // mv.text.get(j));
        }
        for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
            ((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv);
            pw.print(" " + mv.buf);
        }
        pw.println();
    }
    pw.flush();
}
项目:nedis    文件:TestNedisClientImpl.java   
@Test
public void assertCommandEnum() throws IOException {
    ClassReader cr = new ClassReader(NedisClientImpl.class.getName());
    cr.accept(CV, ClassReader.SKIP_DEBUG);
}
项目:astor    文件:ClassReaderGenerator.java   
public ClassReaderGenerator(ClassReader r, int flags) {
    this(r, null, flags);
}
项目:astor    文件:ClassReaderGenerator.java   
public ClassReaderGenerator(ClassReader r, Attribute[] attrs, int flags) {
    this.r = r;
    this.attrs = (attrs != null) ? attrs : new Attribute[0];
    this.flags = flags;
}
项目:astor    文件:AbstractClassLoader.java   
protected ClassGenerator getGenerator(ClassReader r) {
    return new ClassReaderGenerator(r, attributes(), getFlags());
}
项目:astor    文件:DebuggingClassWriter.java   
public byte[] toByteArray() {

return (byte[]) java.security.AccessController.doPrivileged(
  new java.security.PrivilegedAction() {
      public Object run() {


          byte[] b = DebuggingClassWriter.super.toByteArray();
          if (debugLocation != null) {
              String dirs = className.replace('.', File.separatorChar);
              try {
                  new File(debugLocation + File.separatorChar + dirs).getParentFile().mkdirs();

                  File file = new File(new File(debugLocation), dirs + ".class");
                  OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
                  try {
                      out.write(b);
                  } finally {
                      out.close();
                  }

                  if (traceEnabled) {
                      file = new File(new File(debugLocation), dirs + ".asm");
                      out = new BufferedOutputStream(new FileOutputStream(file));
                      try {
                          ClassReader cr = new ClassReader(b);
                          PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
                          TraceClassVisitor tcv = new TraceClassVisitor(null, pw);
                          cr.accept(tcv, 0);
                          pw.flush();
                      } finally {
                          out.close();
                      }
                  }
              } catch (IOException e) {
                  throw new CodeGenerationException(e);
              }
          }
          return b;
       }  
      });

  }
项目:astor    文件:CheckClassAdapter.java   
/**
 * Checks a given class
 * 
 * @param cr a <code>ClassReader</code> that contains bytecode for the
 *        analysis.
 * @param dump true if bytecode should be printed out not only when errors
 *        are found.
 * @param pw write where results going to be printed
 */
public static void verify(
    final ClassReader cr,
    final boolean dump,
    final PrintWriter pw)
{
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn), ClassReader.SKIP_DEBUG);

    Type syperType = cn.superName == null
            ? null
            : Type.getObjectType(cn.superName);
    List methods = cn.methods;
    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = (MethodNode) methods.get(i);
        Analyzer a = new Analyzer(new SimpleVerifier(Type.getObjectType(cn.name),
                syperType,
                false));
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        Frame[] frames = a.getFrames();

        TraceMethodVisitor mv = new TraceMethodVisitor();

        pw.println(method.name + method.desc);
        for (int j = 0; j < method.instructions.size(); ++j) {
            method.instructions.get(j).accept(mv);

            StringBuffer s = new StringBuffer();
            Frame f = frames[j];
            if (f == null) {
                s.append('?');
            } else {
                for (int k = 0; k < f.getLocals(); ++k) {
                    s.append(getShortName(f.getLocal(k).toString()))
                            .append(' ');
                }
                s.append(" : ");
                for (int k = 0; k < f.getStackSize(); ++k) {
                    s.append(getShortName(f.getStack(k).toString()))
                            .append(' ');
                }
            }
            while (s.length() < method.maxStack + method.maxLocals + 1) {
                s.append(' ');
            }
            pw.print(Integer.toString(j + 100000).substring(1));
            pw.print(" " + s + " : " + mv.buf); // mv.text.get(j));
        }
        for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
            ((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv);
            pw.print(" " + mv.buf);
        }
        pw.println();
    }
    pw.flush();
}
项目:astor    文件:ClassReaderGenerator.java   
public ClassReaderGenerator(ClassReader r, int flags) {
    this(r, null, flags);
}
项目:astor    文件:ClassReaderGenerator.java   
public ClassReaderGenerator(ClassReader r, Attribute[] attrs, int flags) {
    this.r = r;
    this.attrs = (attrs != null) ? attrs : new Attribute[0];
    this.flags = flags;
}
项目:astor    文件:AbstractClassLoader.java   
protected ClassGenerator getGenerator(ClassReader r) {
    return new ClassReaderGenerator(r, attributes(), getFlags());
}
项目:astor    文件:DebuggingClassWriter.java   
public byte[] toByteArray() {

return (byte[]) java.security.AccessController.doPrivileged(
  new java.security.PrivilegedAction() {
      public Object run() {


          byte[] b = DebuggingClassWriter.super.toByteArray();
          if (debugLocation != null) {
              String dirs = className.replace('.', File.separatorChar);
              try {
                  new File(debugLocation + File.separatorChar + dirs).getParentFile().mkdirs();

                  File file = new File(new File(debugLocation), dirs + ".class");
                  OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
                  try {
                      out.write(b);
                  } finally {
                      out.close();
                  }

                  if (traceEnabled) {
                      file = new File(new File(debugLocation), dirs + ".asm");
                      out = new BufferedOutputStream(new FileOutputStream(file));
                      try {
                          ClassReader cr = new ClassReader(b);
                          PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
                          TraceClassVisitor tcv = new TraceClassVisitor(null, pw);
                          cr.accept(tcv, 0);
                          pw.flush();
                      } finally {
                          out.close();
                      }
                  }
              } catch (IOException e) {
                  throw new CodeGenerationException(e);
              }
          }
          return b;
       }  
      });

  }
项目:astor    文件:CheckClassAdapter.java   
/**
 * Checks a given class
 * 
 * @param cr a <code>ClassReader</code> that contains bytecode for the
 *        analysis.
 * @param dump true if bytecode should be printed out not only when errors
 *        are found.
 * @param pw write where results going to be printed
 */
public static void verify(
    final ClassReader cr,
    final boolean dump,
    final PrintWriter pw)
{
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn), ClassReader.SKIP_DEBUG);

    Type syperType = cn.superName == null
            ? null
            : Type.getObjectType(cn.superName);
    List methods = cn.methods;
    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = (MethodNode) methods.get(i);
        Analyzer a = new Analyzer(new SimpleVerifier(Type.getObjectType(cn.name),
                syperType,
                false));
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        Frame[] frames = a.getFrames();

        TraceMethodVisitor mv = new TraceMethodVisitor();

        pw.println(method.name + method.desc);
        for (int j = 0; j < method.instructions.size(); ++j) {
            method.instructions.get(j).accept(mv);

            StringBuffer s = new StringBuffer();
            Frame f = frames[j];
            if (f == null) {
                s.append('?');
            } else {
                for (int k = 0; k < f.getLocals(); ++k) {
                    s.append(getShortName(f.getLocal(k).toString()))
                            .append(' ');
                }
                s.append(" : ");
                for (int k = 0; k < f.getStackSize(); ++k) {
                    s.append(getShortName(f.getStack(k).toString()))
                            .append(' ');
                }
            }
            while (s.length() < method.maxStack + method.maxLocals + 1) {
                s.append(' ');
            }
            pw.print(Integer.toString(j + 100000).substring(1));
            pw.print(" " + s + " : " + mv.buf); // mv.text.get(j));
        }
        for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
            ((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv);
            pw.print(" " + mv.buf);
        }
        pw.println();
    }
    pw.flush();
}
项目:mockito-cglib    文件:ClassNameReader.java   
public static String getClassName(ClassReader r) {

    return getClassInfo(r)[0];

}
项目:astor    文件:ClassNameReader.java   
public static String getClassName(ClassReader r) {

    return getClassInfo(r)[0];

}
项目:astor    文件:ClassNameReader.java   
public static String getClassName(ClassReader r) {

    return getClassInfo(r)[0];

}