]> source.dussan.org Git - javassist.git/commitdiff
modified the API to look good.
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Wed, 21 Apr 2004 17:20:21 +0000 (17:20 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Wed, 21 Apr 2004 17:20:21 +0000 (17:20 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@92 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

Readme.html
src/main/javassist/ClassPool.java
src/main/javassist/CtClass.java

index 0d2670b030b7cee40399046d279ba6e62126e534..3c3129c755513b68c10ed354bba0edfab350bc0c 100644 (file)
@@ -258,6 +258,12 @@ see javassist.Dump.
 <p>- version 3.0
 
 <ul>
+  <li>ClassPool has been largely modified.
+      <ul><li>write(), writeFile(), .. in ClassPool were moved to CtClass.
+          <li>The host of javassist.Translator was changed from ClassPool
+              to javassist.Loader.
+      </ul>
+
   <li>javassist.bytecode.annotation has been added.
   <li>The ClassPool framework has been redesigned.
      <ul>
index ee41d99282e2ae0c2910cfaf6619817f5d0d4fcd..78b252d3040d629a81d37df61bea4d8e1405dfa1 100644 (file)
@@ -227,6 +227,8 @@ public class ClassPool {
      *
      * @see CtClass#forName(String)
      * @see CtClass#toClass()
+     * @see #toClass()
+     * @see #forName(String)
      */
     public static class SimpleLoader extends ClassLoader {
         /**
@@ -249,11 +251,15 @@ public class ClassPool {
 
     /**
      * Returns a <code>java.lang.Class</code> object that has been loaded
-     * by <code>loadClass()</code>.  Such an object cannot be
+     * by <code>toClass()</code> in <code>CtClass</code>
+     * or <code>ClassPool</code>.  Such an object cannot be
      * obtained by <code>java.lang.Class.forName()</code> because it has
      * been loaded by an internal class loader of Javassist.
+     *
+     * @param name     the fully-qualified class name.
+     * @see #toClass(CtClass)
      */
-    static Class forName(String name) throws ClassNotFoundException {
+    public Class forName(String name) throws ClassNotFoundException {
         if (classLoader == null)
             classLoader = new SimpleLoader();
 
@@ -261,27 +267,34 @@ public class ClassPool {
     }
 
    /**
-    * Callback to write the class and create a Class object
-    * ClassPool can be extended to override this behavior
-    * @param classname
-    * @param classfile
-    * @return
-    * @throws NotFoundException
-    * @throws IOException
-    * @throws CannotCompileException
+    * Loads the class represented by a <code>CtClass</code> object.
+    * <code>toClass()</code> in <code>CtClass</code> calls this method
+    * to load a class.
+    *
+    * <p>This method can be overridden to change the class loader.
+    * In the default implementation,
+    * the class loader is a <code>SimpleLoader</code>.
+    * If this method is overridden, <code>forName()</code> must be also
+    * overridden for extending the behavior.
+    *
+    * @param cc     the loaded <code>CtClass</code>.
+    * @return   the <code>java.lang.Class</code> object representing
+    *           the loaded class.
+    * @see #forName(String)
     */
-   public Class writeAsClass(String classname, byte[] classfile)
-       throws CannotCompileException
-   {
-       try {
-          if (classLoader == null)
-              classLoader = new SimpleLoader();
-           return classLoader.loadClass(classname, classfile);
-       }
-       catch (ClassFormatError e) {
-           throw new CannotCompileException(e, classname);
-       }
-   }
+    public Class toClass(CtClass cc)
+        throws NotFoundException, CannotCompileException, IOException
+    {
+        try {
+            if (classLoader == null)
+                classLoader = new SimpleLoader();
+
+            return classLoader.loadClass(cc.getName(), cc.toBytecode());
+        }
+        catch (ClassFormatError e) {
+            throw new CannotCompileException(e, cc.getName());
+        }
+    }
 
    /**
      * Reads a class file and constructs a <code>CtClass</code>
index d3bc537928ec0e5ba5ee7082a569ee5b3a74697d..41fa0dfe678095ed3bd17101194817a6c92e1926 100644 (file)
@@ -849,7 +849,7 @@ public abstract class CtClass {
     public Class toClass()
         throws NotFoundException, IOException, CannotCompileException
     {
-        return getClassPool().writeAsClass(getName(), toBytecode());
+        return getClassPool().toClass(this);
     }
 
     /**
@@ -861,8 +861,8 @@ public abstract class CtClass {
      * @see CtClass#toClass()
      * @see ClassPool.SimpleLoader
      */
-    public static Class forName(String name) throws ClassNotFoundException {
-        return ClassPool.forName(name);
+    public Class forName(String name) throws ClassNotFoundException {
+        return getClassPool().forName(name);
     }
 
     /**