Browse Source

modified the API to look good.


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@92 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
chiba 20 years ago
parent
commit
9972682683
3 changed files with 44 additions and 25 deletions
  1. 6
    0
      Readme.html
  2. 35
    22
      src/main/javassist/ClassPool.java
  3. 3
    3
      src/main/javassist/CtClass.java

+ 6
- 0
Readme.html View File

<p>- version 3.0 <p>- version 3.0


<ul> <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>javassist.bytecode.annotation has been added.
<li>The ClassPool framework has been redesigned. <li>The ClassPool framework has been redesigned.
<ul> <ul>

+ 35
- 22
src/main/javassist/ClassPool.java View File

* *
* @see CtClass#forName(String) * @see CtClass#forName(String)
* @see CtClass#toClass() * @see CtClass#toClass()
* @see #toClass()
* @see #forName(String)
*/ */
public static class SimpleLoader extends ClassLoader { public static class SimpleLoader extends ClassLoader {
/** /**


/** /**
* Returns a <code>java.lang.Class</code> object that has been loaded * 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 * obtained by <code>java.lang.Class.forName()</code> because it has
* been loaded by an internal class loader of Javassist. * 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) if (classLoader == null)
classLoader = new SimpleLoader(); classLoader = new SimpleLoader();


} }


/** /**
* 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> * Reads a class file and constructs a <code>CtClass</code>

+ 3
- 3
src/main/javassist/CtClass.java View File

public Class toClass() public Class toClass()
throws NotFoundException, IOException, CannotCompileException throws NotFoundException, IOException, CannotCompileException
{ {
return getClassPool().writeAsClass(getName(), toBytecode());
return getClassPool().toClass(this);
} }


/** /**
* @see CtClass#toClass() * @see CtClass#toClass()
* @see ClassPool.SimpleLoader * @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);
} }


/** /**

Loading…
Cancel
Save