Package org.objectweb.asm

Examples of org.objectweb.asm.ClassReader


    byte[] classData = getCode( classUrl.openStream());
   
    StringWriter sw = new StringWriter();
    ASMifierClassVisitor cv = new ASMifierClassVisitor( new PrintWriter( sw));
   
    ClassReader cr = new ClassReader( classData);
    cr.accept(cv, PrintClassVisitor.getDefaultAttributes(), false);

    String name = classUrl.getFile();
    String generated = sw.toString();
   
    String cname = name.substring( name.lastIndexOf( '/')+1, name.length()-".class".length())+"Dump";
View Full Code Here


  }
 
 
  private static String traceBytecode( byte[] classData) {
    StringWriter sw = new StringWriter();
    ClassReader cr = new ClassReader( classData);
    // cr.accept( new TraceClassVisitor( cw, new PrintWriter( System.out)),
    cr.accept( new TraceClassVisitor( null, new PrintWriter( sw)), Attributes.getDefaultAttributes(), false);
    return sw.toString();
  }
View Full Code Here

  }

  public void testRoundtrip() throws Exception {
    byte[] classData = getCode( new URL( className).openStream());
   
    ClassReader cr = new ClassReader( classData);
    ClassWriter cw = new ClassWriter( false, false);
    cr.accept(cw, Attributes.getDefaultAttributes(), false);
    byte[] newData = cw.toByteArray();

    try {
    assertTrue( Arrays.equals( classData, newData));
     
View Full Code Here

    }
  }
 
  private static void traceBytecode( byte[] classData, PrintWriter pw) {
    ClassReader cr = new ClassReader( classData);
    // cr.accept( new TraceClassVisitor( cw, new PrintWriter( System.out)),
    cr.accept( new TraceClassVisitor( null, pw), Attributes.getDefaultAttributes(), false);
  }
View Full Code Here

     * edu.umd.cs.findbugs.classfile.IAnalysisEngine#analyze(edu.umd.cs.findbugs
     * .classfile.IAnalysisCache, java.lang.Object)
     */
    @Override
    public ClassNode analyze(IAnalysisCache analysisCache, ClassDescriptor descriptor) throws CheckedAnalysisException {
        ClassReader classReader = analysisCache.getClassAnalysis(ClassReader.class, descriptor);

        ICodeBaseEntry entry = analysisCache.getClassPath().lookupResource(descriptor.toResourceName());

        // One of the less-than-ideal features of ASM is that
        // invalid classfile format is indicated by a
        // random runtime exception rather than something
        // indicative of the real problem.
        try {
            ClassNode cn = new ClassNode();
            classReader.accept(cn, 0);
            return cn;
        } catch (RuntimeException e) {
            throw new InvalidClassFileFormatException(descriptor, entry, e);
        }
    }
View Full Code Here

public class BytecodeChecker implements ClassChecker {
    ClassStructureAdapter adapter;

    public BytecodeChecker(byte[] buffer) {
        // run a pass over the bytecode to identify the interfaces
        ClassReader cr = new ClassReader(buffer);
        adapter = new ClassStructureAdapter();
        cr.accept(adapter, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
    }
View Full Code Here

    LOGGER.debug("New class name: {}", newClassName);
    LOGGER.debug("Full new class name: {}", fullNewClassName);

    Class<?> clazz = null;
    try {
      ClassReader cReader = new ClassReader(loader.getResourceAsStream(aClass.getName().replaceAll(
          "\\.", "/")
          + ".class"));
      ClassWriter cWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
      ClassVisitor dynamicSubclassAdapter = new ProxySubclassAdapter(cWriter, fullNewClassName,
          loader);
View Full Code Here

      InputStream is = loader.getResourceAsStream(superName +".class");
   
      if(is == null)
        throw new IOException();
     
      new ClassReader(is).accept(cf, ClassReader.SKIP_FRAMES + ClassReader.SKIP_DEBUG + ClassReader.SKIP_CODE);
    } catch (IOException ioe) {
      UnableToProxyException u = new UnableToProxyException(name, ioe);
      throw new RuntimeException(NLS.MESSAGES.getMessage("cannot.load.superclass", superName.replace('/', '.'), typeBeingWoven.getClassName()), u);
    }
    return cf.hasNoArgsConstructor();
View Full Code Here

  public static void readClass(Class<?> c, ClassVisitor adapter) throws IOException {
    String className = c.getName();
    className = className.substring(className.lastIndexOf('.') + 1) + ".class";
       
    //Load the class bytes and copy methods across
    ClassReader cReader = new ClassReader(c.getResourceAsStream(className));

    cReader.accept(adapter, ClassReader.SKIP_CODE |
        ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
  }
View Full Code Here

      setOfFoundMethods.removeAll(setOfObservedMethods);
      try {
        // read the current class and use a
        // ProxySubclassHierarchyAdapter
        // to process only methods on that class that are in the list
        ClassReader cr = new ClassReader(loader.getResourceAsStream(currentlyAnalysedClass
            .getName().replaceAll("\\.", "/")
            + ".class"));
        ClassVisitor hierarchyAdapter = new ProxySubclassHierarchyAdapter(this, setOfFoundMethods);
        cr.accept(hierarchyAdapter, ClassReader.SKIP_DEBUG);
      } catch (IOException e) {
        throw new TypeNotPresentException(currentlyAnalysedClassName, e);
      }
      // now add the foundMethods to the overall list of observed methods
      setOfObservedMethods.addAll(setOfFoundMethods);
View Full Code Here

TOP

Related Classes of org.objectweb.asm.ClassReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.