当前位置: 首页>>代码示例>>Java>>正文


Java ClassReader类代码示例

本文整理汇总了Java中org.mockito.asm.ClassReader的典型用法代码示例。如果您正苦于以下问题:Java ClassReader类的具体用法?Java ClassReader怎么用?Java ClassReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClassReader类属于org.mockito.asm包,在下文中一共展示了ClassReader类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getClassInfo

import org.mockito.asm.ClassReader; //导入依赖的package包/类
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[]{} );
}
 
开发者ID:mockito,项目名称:mockito-cglib,代码行数:26,代码来源:ClassNameReader.java

示例2: ClassReaderGenerator

import org.mockito.asm.ClassReader; //导入依赖的package包/类
public ClassReaderGenerator(ClassReader r, int flags) {
    this(r, null, flags);
}
 
开发者ID:mockito,项目名称:mockito-cglib,代码行数:4,代码来源:ClassReaderGenerator.java

示例3: getGenerator

import org.mockito.asm.ClassReader; //导入依赖的package包/类
protected ClassGenerator getGenerator(ClassReader r) {
    return new ClassReaderGenerator(r, attributes(), getFlags());
}
 
开发者ID:mockito,项目名称:mockito-cglib,代码行数:4,代码来源:AbstractClassLoader.java

示例4: toByteArray

import org.mockito.asm.ClassReader; //导入依赖的package包/类
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;
       }  
      });
      
  }
 
开发者ID:mockito,项目名称:mockito-cglib,代码行数:44,代码来源:DebuggingClassWriter.java

示例5: verify

import org.mockito.asm.ClassReader; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:mockito,项目名称:mockito-cglib,代码行数:72,代码来源:CheckClassAdapter.java

示例6: assertCommandEnum

import org.mockito.asm.ClassReader; //导入依赖的package包/类
@Test
public void assertCommandEnum() throws IOException {
    ClassReader cr = new ClassReader(NedisClientImpl.class.getName());
    cr.accept(CV, ClassReader.SKIP_DEBUG);
}
 
开发者ID:CodisLabs,项目名称:nedis,代码行数:6,代码来源:TestNedisClientImpl.java

示例7: getClassName

import org.mockito.asm.ClassReader; //导入依赖的package包/类
public static String getClassName(ClassReader r) {

    return getClassInfo(r)[0];
  
}
 
开发者ID:mockito,项目名称:mockito-cglib,代码行数:6,代码来源:ClassNameReader.java


注:本文中的org.mockito.asm.ClassReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。