From: chiba Date: Mon, 4 Aug 2003 15:47:33 +0000 (+0000) Subject: updated some javadoc comments. X-Git-Tag: rel_3_17_1_ga~575 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d96924c601912c7df55e378806a126850a798eaa;p=javassist.git updated some javadoc comments. modified Loader so that getPackage() works. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@32 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/Readme.html b/Readme.html index 0f319d68..9aaf4bae 100644 --- a/Readme.html +++ b/Readme.html @@ -242,6 +242,8 @@ see javassist.Dump.
  • CtConstructor.setBody() now works for class initializers.
  • CtNewMethod.delegator() now works for static methods.
  • javassist.expr.Expr.indexOfBytecode() has been added. +
  • javassist.Loader has been modified so that getPackage() returns + a package object.

    - version 2.5.1 in May, 2003. diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index 509cf8d8..07a442ef 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -372,7 +372,7 @@ public class ClassPool { /** * Returns a java.lang.Class object that has been loaded - * by writeAsClass(). Note that such a class cannot be + * by writeAsClass(). Note that such an object cannot be * obtained by java.lang.Class.forName() because it has * been loaded by an internal class loader. * @@ -399,9 +399,20 @@ public class ClassPool { * loads only the classes explicitly specified by this method * writeAsClass(). The other classes are loaded * by the parent class loader (the sytem class loader) by delegation. - * Thus, if a class X loaded by the internal class - * loader refers to a class Y, then the class - * Y is loaded by the parent class loader. + * + *

    For example, + * + *

    + * + *

    If the class Line is loaded by the internal class + * loader and the class Point has not been loaded yet, + * then the class Point that the class Line + * refers to is loaded by the parent class loader. There is no + * chance of modifying the definition of Point with + * Javassist. + * + *

    The internal class loader is shared among all the instances + * of ClassPool. * * @param classname a fully-qualified class name. * diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index 055e12dd..bb8c46cb 100644 --- a/src/main/javassist/CtClass.java +++ b/src/main/javassist/CtClass.java @@ -174,8 +174,10 @@ public abstract class CtClass { public boolean isModified() { return false; } /** - * Returns true if the class has been loaded and thus it cannot be - * modified any more. + * Returns true if the class has been loaded or written out + * and thus it cannot be modified any more. + * + * @see #defrost() */ public boolean isFrozen() { return true; } @@ -189,12 +191,14 @@ public abstract class CtClass { } /** - * Defrosts the class so that the class can be modified. + * Defrosts the class so that the class can be modified again. * - * To avoid changes that are never reflected, + * To avoid changes that will be never reflected, * the class is frozen to be unmodifiable if it is loaded or * written out. This method should be called only in a case * that the class will be reloaded or written out later again. + * + * @see #isFrozen() */ public void defrost() { throw new RuntimeException("cannot defrost " + getName()); @@ -753,6 +757,8 @@ public abstract class CtClass { * *

    See the description of ClassPool.writeAsClass() * before you use this method. + * This method is provided for convenience. If you need more + * complex functionality, you should write your own class loader. * * @see javassist.ClassPool#writeAsClass(String) * @see javassist.ClassPool#forName(String) diff --git a/src/main/javassist/Loader.java b/src/main/javassist/Loader.java index c418aefb..02ccfcfd 100644 --- a/src/main/javassist/Loader.java +++ b/src/main/javassist/Loader.java @@ -296,6 +296,20 @@ public class Loader extends ClassLoader { return null; } + int i = name.lastIndexOf('.'); + if (i != -1) { + String pname = name.substring(0, i); + if (getPackage(pname) == null) + try { + definePackage(pname, null, null, null, + null, null, null, null); + } + catch (IllegalArgumentException e) { + // ignore. maybe the package object for the same + // name has been created just right away. + } + } + return defineClass(name, classfile, 0, classfile.length); } @@ -343,4 +357,18 @@ public class Loader extends ClassLoader { else return findSystemClass(classname); } + + protected Package getPackage(String name) { + return super.getPackage(name); + } + /* + // Package p = super.getPackage(name); + Package p = null; + if (p == null) + return definePackage(name, null, null, null, + null, null, null, null); + else + return p; + } + */ } diff --git a/src/main/javassist/expr/Expr.java b/src/main/javassist/expr/Expr.java index 2764767d..8b4e9170 100644 --- a/src/main/javassist/expr/Expr.java +++ b/src/main/javassist/expr/Expr.java @@ -35,6 +35,9 @@ public abstract class Expr implements Opcode { static final String javaLangObject = "java.lang.Object"; + /** + * Undocumented constructor. Do not use; internal-use only. + */ protected Expr(int pos, CodeIterator i, CtClass declaring, MethodInfo m) { currentPos = pos; iterator = i; diff --git a/tutorial/tutorial2.html b/tutorial/tutorial2.html index 31d75f0b..13574c96 100644 --- a/tutorial/tutorial2.html +++ b/tutorial/tutorial2.html @@ -23,6 +23,32 @@ the Java reflection API. CtClass provides definition. It allows to add a new field, constructor, and method. Instrumenting a method body is also possible. +

    +Methods are represented by CtMethod objects. +CtMethod provides several methods for modifying +the definition of the method. Note that if a method is inherited +from a super class, then +the same CtMethod object +that represents the inherited method represents the method declared +in that super class. +A CtMethod object corresponds to every method declaration. + +

    +For example, if class Point declares method move() +and a subclass ColorPoint of Point does +not override move(), the two move() methods +declared in Point and inherited in ColorPoint +are represented by the identical CtMethod object. +If the method definition represented by this +CtMethod object is modified, the modification is +reflected on both the methods. +If you want to modify only the move() method in +ColorPoint, you first have to add to ColorPoint +a copy of the CtMethod object representing move() +in Point. A copy of the the CtMethod object +can be obtained by CtNewMethod.copy(). + +