Package javassist.bytecode

Examples of javassist.bytecode.ClassFile


    }

    public void removeConstructor(CtConstructor m) throws NotFoundException {
        checkModify();
        MethodInfo mi = m.getMethodInfo2();
        ClassFile cf = getClassFile2();
        if (cf.getMethods().remove(mi)) {
            getMembers().remove(m);
            gcConstPool = true;
        }
        else
            throw new NotFoundException(m.toString());
View Full Code Here


    }

    public void removeMethod(CtMethod m) throws NotFoundException {
        checkModify();
        MethodInfo mi = m.getMethodInfo2();
        ClassFile cf = getClassFile2();
        if (cf.getMethods().remove(mi)) {
            getMembers().remove(m);
            gcConstPool = true;
        }
        else
            throw new NotFoundException(m.toString());
View Full Code Here

            return ai.get();
    }

    public void setAttribute(String name, byte[] data) {
        checkModify();
        ClassFile cf = getClassFile2();
        cf.addAttribute(new AttributeInfo(cf.getConstPool(), name, data));
    }
View Full Code Here

    public void instrument(CodeConverter converter)
        throws CannotCompileException
    {
        checkModify();
        ClassFile cf = getClassFile2();
        ConstPool cp = cf.getConstPool();
        List list = cf.getMethods();
        int n = list.size();
        for (int i = 0; i < n; ++i) {
            MethodInfo minfo = (MethodInfo)list.get(i);
            converter.doit(this, minfo, cp);
        }
View Full Code Here

    public void instrument(ExprEditor editor)
        throws CannotCompileException
    {
        checkModify();
        ClassFile cf = getClassFile2();
        List list = cf.getMethods();
        int n = list.size();
        for (int i = 0; i < n; ++i) {
            MethodInfo minfo = (MethodInfo)list.get(i);
            editor.doit(this, minfo);
        }
View Full Code Here

        throws CannotCompileException, IOException
    {
        try {
            if (isModified()) {
                checkPruned("toBytecode");
                ClassFile cf = getClassFile2();
                if (gcConstPool) {
                    cf.compact();
                    gcConstPool = false;
                }

                modifyClassConstructor(cf);
                modifyConstructors(cf);
                if (debugDump != null)
                    dumpClassFile(cf);

                cf.write(out);
                out.flush();
                fieldInitializers = null;
                if (doPruning) {
                    // to save memory
                    cf.prune();
                    wasPruned = true;
                }
            }
            else {
                classPool.writeClassfile(getName(), out);
View Full Code Here

            return;
        }

        DataInputStream in = new DataInputStream(
                                         new FileInputStream(args[0]));
        ClassFile w = new ClassFile(in);
        PrintWriter out = new PrintWriter(System.out, true);
        out.println("*** constant pool ***");
        w.getConstPool().print(out);
        out.println();
        out.println("*** members ***");
        ClassFilePrinter.print(w, out);
    }
View Full Code Here

     * <p>This method may return <code>null</code>.
     *
     * @return a <code>Collection&lt;String&gt;</code> object.
     */
    public synchronized Collection getRefClasses() {
        ClassFile cf = getClassFile2();
        if (cf != null) {
            ClassMap cm = new ClassMap() {
                public void put(String oldname, String newname) {
                    put0(oldname, newname);
                }

                public Object get(Object jvmClassName) {
                    String n = toJavaName((String)jvmClassName);
                    put0(n, n);
                    return null;
                }

                public void fix(String name) {}
            };
            cf.getRefClasses(cm);
            return cm.values();
        }
        else
            return null;
    }
View Full Code Here

    filter = f;
  }

  public void transform(File file) throws Exception {
    DataInputStream in = new DataInputStream(new FileInputStream(file));
    ClassFile classfile = new ClassFile(in);
    transform(classfile);
    DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
    try {
      classfile.write(out);
    } finally {
      out.close();
    }
  }
View Full Code Here

      ClassLoader loader,
      String className,
      Class classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer) {
    ClassFile classfile;
    try {
      // WARNING: classfile only
      classfile = new ClassFile( new DataInputStream( new ByteArrayInputStream( classfileBuffer ) ) );
    }
    catch (IOException e) {
      log.error( "Unable to build enhancement metamodel for " + className );
      return classfileBuffer;
    }
    FieldTransformer transformer = getFieldTransformer( classfile );
    if ( transformer != null ) {
      if ( log.isDebugEnabled() ) {
        log.debug( "Enhancing " + className );
      }
      DataOutputStream out = null;
      try {
        transformer.transform( classfile );
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        out = new DataOutputStream( byteStream );
        classfile.write( out );
        return byteStream.toByteArray();
      }
      catch (Exception e) {
        log.error( "Unable to transform class", e );
        throw new HibernateException( "Unable to transform class: " + e.getMessage() );
View Full Code Here

TOP

Related Classes of javassist.bytecode.ClassFile

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.