[jboss-cvs] javassist/src/main/javassist ...

Shigeru Chiba chiba at is.titech.ac.jp
Thu Sep 11 06:40:08 EDT 2008


  User: chiba   
  Date: 08/09/11 06:40:08

  Modified:    src/main/javassist   CtClass.java ClassPool.java
  Log:
  implemented ClassPool.makeClassIfNew()
  
  Revision  Changes    Path
  1.101     +1 -1      javassist/src/main/javassist/CtClass.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CtClass.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtClass.java,v
  retrieving revision 1.100
  retrieving revision 1.101
  diff -u -b -r1.100 -r1.101
  --- CtClass.java	4 Jul 2008 09:17:50 -0000	1.100
  +++ CtClass.java	11 Sep 2008 10:40:08 -0000	1.101
  @@ -52,7 +52,7 @@
       /**
        * The version number of this release.
        */
  -    public static final String version = "3.8.1.GA";
  +    public static final String version = "3.9.0.GA";
   
       /**
        * Prints the version number and the copyright notice.
  
  
  
  1.67      +54 -0     javassist/src/main/javassist/ClassPool.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ClassPool.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/ClassPool.java,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -b -r1.66 -r1.67
  --- ClassPool.java	4 Jul 2008 09:17:50 -0000	1.66
  +++ ClassPool.java	11 Sep 2008 10:40:08 -0000	1.67
  @@ -547,6 +547,8 @@
        * This method throws an exception if the class is already frozen or
        * if this class pool cannot edit the class since it is in a parent
        * class pool.
  +     *
  +     * @see checkNotExists(String)
        */
       void checkNotFrozen(String classname) throws RuntimeException {
           CtClass clazz = getCached(classname);
  @@ -567,6 +569,25 @@
                                           + ": frozen class (cannot edit)");
       }
   
  +    /*
  +     * This method returns null if this or its parent class pool does
  +     * not contain a CtClass object with the class name.
  +     *
  +     * @see checkNotFrozen(String)
  +     */
  +    CtClass checkNotExists(String classname) {
  +        CtClass clazz = getCached(classname);
  +        if (clazz == null)
  +            if (!childFirstLookup && parent != null) {
  +                try {
  +                    clazz = parent.get0(classname, true);
  +                }
  +                catch (NotFoundException e) {}
  +            }
  +
  +        return clazz;
  +    }
  +
       /* for CtClassType.getClassFile2().  Don't delegate to the parent.
        */
       InputStream openClassfile(String classname) throws NotFoundException {
  @@ -628,6 +649,7 @@
        * @param classfile class file.
        * @throws RuntimeException if there is a frozen class with the
        *                          the same name.
  +     * @see #makeClassIfNew(InputStream)
        * @see javassist.ByteArrayClassPath
        */
       public CtClass makeClass(InputStream classfile)
  @@ -666,6 +688,38 @@
       }
   
       /**
  +     * Creates a new class (or interface) from the given class file.
  +     * If there already exists a class with the same name, this method
  +     * returns the existing class; a new class is never created from
  +     * the given class file.
  +     *
  +     * <p>This method is used for creating a <code>CtClass</code> object
  +     * directly from a class file.  The qualified class name is obtained
  +     * from the class file; you do not have to explicitly give the name.
  +     *
  +     * @param classfile             the class file.
  +     * @see #makeClass(InputStream)
  +     * @see javassist.ByteArrayClassPath
  +     * @since 3.9
  +     */
  +    public CtClass makeClassIfNew(InputStream classfile)
  +        throws IOException, RuntimeException
  +    {
  +        compress();
  +        classfile = new BufferedInputStream(classfile);
  +        CtClass clazz = new CtClassType(classfile, this);
  +        clazz.checkModify();
  +        String classname = clazz.getName();
  +        CtClass found = checkNotExists(classname);
  +        if (found != null)
  +            return found;
  +        else {
  +            cacheCtClass(classname, clazz, true);
  +            return clazz;
  +        }
  +    }
  +
  +    /**
        * Creates a new public class.
        * If there already exists a class with the same name, the new class
        * overwrites that previous class.
  
  
  



More information about the jboss-cvs-commits mailing list