Package net.sf.joafip.asm

Examples of net.sf.joafip.asm.ClassReader


   */
  public byte[] generate(final String className, final byte[] originalCode,
      final int off, final int len) {

    final EnumTransformationType transformationTypeFromProperties = transformAttribute(className);
    final ClassReader classReader = new ClassReader(originalCode, off, len);
    final IMethodMap methodMap = new MethodMap();
    final Set<String> syntheticFieldSet = new TreeSet<String>();
    final ClassVisitorForStorable classVisitorForStorable = new ClassVisitorForStorable();
    classVisitorForStorable.setMethodMap(methodMap, syntheticFieldSet);
    // must not skip code to compute max locals
    classReader.accept(classVisitorForStorable, /* ClassReader.SKIP_CODE | */
        ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);

    // annotation override instrumentation properties
    transformationAttribute = classVisitorForStorable
        .getTransformationType();
    if (transformationAttribute == null) {
      transformationAttribute = transformationTypeFromProperties;
    }

    final String[] splitedClassName = className.split(POINT_REGEX);
    final PackageNode node = packageMgr.addPackage(splitedClassName, 0,
        splitedClassName.length, transformationAttribute);

    byte[] code = null;
    if (EnumTransformationType.NONE.equals(transformationAttribute)
        && !methodMap.hasMethodToTransform()) {
      transformed = false;
    } else {
      transformed = true;
    }

    if (transformed) {

      // //FIX-MELUC ____for test
      // ClassNode cn = new ClassNode();
      // ClassVisitor classVisitor = new ClassVisitorForPersistable(
      // cn, methodMap, syntheticFieldSet,
      // forStorableTranform && (!notStorableAnnotation),
      // storableAccess);
      // classReader = new ClassReader(originalCode, off, len);
      // classReader.accept(classVisitor, 0);
      // try {
      // PrintWriter pw=new PrintWriter("logs/generated.txt");
      // CheckClassAdapter.verify(cn, null/*loader*/, true/*dump*/, pw);
      // } catch (Exception e) {
      // e.printStackTrace();
      // }
      //
      // //end for test

      final ClassWriter classWriter = new AgentClassWriter(
          ClassWriter.COMPUTE_FRAMES);

      final ClassVisitor classVisitor = new ClassVisitorForPersistable(
          classWriter, methodMap, syntheticFieldSet,
          transformationAttribute, node);

      // classReader = new ClassReader(originalCode, off, len);
      classReader.accept(classVisitor, 0);
      code = classWriter.toByteArray();
    }
    return code;
  }
View Full Code Here


  public AgentClassInfo(final String type, final ClassLoader loader) {
    this.loader = loader;
    this.type = Type.getType("L" + type + ";");
    final String classResourceName = type.replace('.', '/') + ".class";
    InputStream inputStream = null;
    ClassReader classReader;
    try {
      inputStream = loader.getResourceAsStream(classResourceName);
      classReader = new ClassReader(inputStream);
    } catch (IOException e) {
      throw new RuntimeException(e);// NOPMD
    } finally {
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (Exception e) {// NOPMD ignore error
        }
      }
    }

    // optimized version
    // int h = cr.header;
    // access = cr.readUnsignedShort(h);
    // final char[] buf = new char[2048];
    // String name = cr.readClass( cr.header + 2, buf);

    // final int v = cr.getItem(cr.readUnsignedShort(h + 4));
    // superClass = v == 0 ? null : cr.readUTF8(v, buf);
    // interfaces = new String[cr.readUnsignedShort(h + 6)];
    // h += 8;
    // for (int i = 0; i < interfaces.length; ++i) {
    // interfaces[i] = cr.readClass(h, buf);
    // h += 2;
    // }
    access = classReader.getAccess();
    superClass = classReader.getSuperName();
    interfaces = classReader.getInterfaces();
  }
View Full Code Here

TOP

Related Classes of net.sf.joafip.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.