Package org.objectweb.asm

Examples of org.objectweb.asm.ClassReader


  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


      String unable = null;
      while(aRunning || bRunning ) {
        if(aRunning) {
          is = loader.getResourceAsStream(arg00 + ".class");
          if(is != null) {
            ClassReader cr = new ClassReader(is);
            arg00 = cr.getSuperName();
            if(arg00 == null)
              aRunning = false;
            else if(!!!names.add(arg00))
              return arg00;
          } else {
            //The class file isn't visible on this ClassLoader
            unable = arg0;
            aRunning = false;
          }
        }
        if(bRunning) {
          is = loader.getResourceAsStream(arg11 + ".class");
          if(is != null) {
            ClassReader cr = new ClassReader(is);
            arg11 = cr.getSuperName();
            if(arg11 == null)
              bRunning = false;
            else if(!!!names.add(arg11))
              return arg11;
          } else {
View Full Code Here

* This class is used to weave the bytes of a class into a proxyable class
*/
public final class WovenProxyGenerator
{
  public static final byte[] getWovenProxy(byte[] original, String className, ClassLoader loader){
    ClassReader cReader = new ClassReader(original);
    //Don't weave interfaces, enums or annotations
    if((cReader.getAccess() & (ACC_INTERFACE | ACC_ANNOTATION | ACC_ENUM)) != 0)
      return null;
   
    //If we are Java 1.6 + compiled then we need to compute stack frames, otherwise
    //maxs are fine (and faster)
    ClassWriter cWriter = new OSGiFriendlyClassWriter(cReader, AbstractWovenProxyAdapter.IS_AT_LEAST_JAVA_6 ?
            ClassWriter.COMPUTE_FRAMES : ClassWriter.COMPUTE_MAXS, loader);
   
    //Wrap our outer layer to add the original SerialVersionUID if it was previously being defaulted
    ClassVisitor weavingAdapter = new SyntheticSerialVerUIDAdder(
                               new WovenProxyAdapter(cWriter, className, loader));
   
    // If we are Java 1.6 + then we need to skip frames as they will be recomputed
    cReader.accept(weavingAdapter, AbstractWovenProxyAdapter.IS_AT_LEAST_JAVA_6 ? ClassReader.SKIP_FRAMES : 0);
   
    return cWriter.toByteArray();
  }
View Full Code Here

    * Fast-parse the given class bytecode to determine if it is an
    * annotation class.
    */
   private static boolean isAnnotationClass(byte[] bytes) {
       IsAnnotationVisitor isAnnotationVisitor = new IsAnnotationVisitor();
       ClassReader classReader = new ClassReader(bytes);
       classReader.accept(isAnnotationVisitor, ClassReader.SKIP_DEBUG);
       return isAnnotationVisitor.isAnnotation;
   }
View Full Code Here

    * Fast-parse the given class bytecode to determine if it is an
    * annotation class.
    */
   private static boolean isAnnotationClass(byte[] bytes) {
       IsAnnotationVisitor isAnnotationVisitor = new IsAnnotationVisitor();
       ClassReader classReader = new ClassReader(bytes);
       classReader.accept(isAnnotationVisitor, true);
       return isAnnotationVisitor.isAnnotation;
   }
View Full Code Here

      ClassLoader loader,
      String className,
      Class classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer) {
    ClassReader reader;
    try {
      reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
    }
    catch (IOException e) {
      log.error( "Unable to read class", e );
      throw new HibernateException( "Unable to read class: " + e.getMessage() );
    }

    String[] names = ClassNameReader.getClassInfo( reader );
    ClassWriter w = new DebuggingClassWriter( true );
    ClassTransformer t = getClassTransformer( names );
    if ( t != null ) {
      if ( log.isDebugEnabled() ) {
        log.debug( "Enhancing " + className );
      }
      ByteArrayOutputStream out;
      byte[] result;
      try {
        reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
        new TransformingClassGenerator(
            new ClassReaderGenerator( reader, attributes(), skipDebug() ), t
        ).generateClass( w );
        out = new ByteArrayOutputStream();
        out.write( w.toByteArray() );
View Full Code Here

    private final String name;
    private final boolean isInstrumented;

    public CustomClassDescriptor(byte[] bytecode) throws Exception {
      this.bytecode = bytecode;
      ClassReader reader = new ClassReader( new ByteArrayInputStream( bytecode ) );
      String[] names = ClassNameReader.getClassInfo( reader );
      this.name = names[0];
      boolean instrumented = false;
      for ( int i = 1; i < names.length; i++ ) {
        if ( InterceptFieldEnabled.class.getName().equals( names[i] ) ) {
View Full Code Here

  }

  public void transform(WovenClass wovenClass) {
    byte[] bytes = wovenClass.getBytes();

    ClassReader cr = new ClassReader(bytes);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS
        | ClassWriter.COMPUTE_FRAMES);
    cr.accept(cw, 0);

    Method md = Method
        .getMethod("org.eclipse.swt.graphics.Color getForeground ()");
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, md.getName(),
        md.getDescriptor(), null, null);
View Full Code Here

   
    byte[] bytes = null;
   
    public WovenClassImpl(Class clazz) {
      try {
        ClassReader cr = new ClassReader(clazz.getName());
        ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
        cr.accept(cw, 0);
        bytes = cw.toByteArray();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
View Full Code Here

        for (Iterator entryIter = declToBridge.entrySet().iterator(); entryIter.hasNext(); ) {
            Map.Entry entry = (Map.Entry)entryIter.next();
            Class owner = (Class)entry.getKey();
            Set bridges = (Set)entry.getValue();
            try {
                new ClassReader(owner.getName())
                  .accept(new BridgedFinder(bridges, resolved),
                          ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG);
            } catch(IOException ignored) {}
        }
        return resolved;
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.