aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-08-04 15:47:33 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-08-04 15:47:33 +0000
commitd96924c601912c7df55e378806a126850a798eaa (patch)
tree1be4090c1e6ca1bf8c6bf5dfbaac40360c2aaa15
parent4fc98e20925d92a81cb8e2076886c841993af1c5 (diff)
downloadjavassist-d96924c601912c7df55e378806a126850a798eaa.tar.gz
javassist-d96924c601912c7df55e378806a126850a798eaa.zip
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
-rw-r--r--Readme.html2
-rw-r--r--src/main/javassist/ClassPool.java19
-rw-r--r--src/main/javassist/CtClass.java14
-rw-r--r--src/main/javassist/Loader.java28
-rw-r--r--src/main/javassist/expr/Expr.java3
-rw-r--r--tutorial/tutorial2.html26
6 files changed, 84 insertions, 8 deletions
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.
<li>CtConstructor.setBody() now works for class initializers.
<li>CtNewMethod.delegator() now works for static methods.
<li>javassist.expr.Expr.indexOfBytecode() has been added.
+ <li>javassist.Loader has been modified so that getPackage() returns
+ a package object.
</ul>
<p>- 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 <code>java.lang.Class</code> object that has been loaded
- * by <code>writeAsClass()</code>. Note that such a class cannot be
+ * by <code>writeAsClass()</code>. Note that such an object cannot be
* obtained by <code>java.lang.Class.forName()</code> 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
* <code>writeAsClass()</code>. The other classes are loaded
* by the parent class loader (the sytem class loader) by delegation.
- * Thus, if a class <code>X</code> loaded by the internal class
- * loader refers to a class <code>Y</code>, then the class
- * <code>Y</code> is loaded by the parent class loader.
+ *
+ * <p>For example,
+ *
+ * <ul><pre>class Line { Point p1, p2; }</pre></ul>
+ *
+ * <p>If the class <code>Line</code> is loaded by the internal class
+ * loader and the class <code>Point</code> has not been loaded yet,
+ * then the class <code>Point</code> that the class <code>Line</code>
+ * refers to is loaded by the parent class loader. There is no
+ * chance of modifying the definition of <code>Point</code> with
+ * Javassist.
+ *
+ * <p>The internal class loader is shared among all the instances
+ * of <code>ClassPool</code>.
*
* @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 {
*
* <p>See the description of <code>ClassPool.writeAsClass()</code>
* 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. <code>CtClass</code> provides
definition. It allows to add a new field, constructor, and method.
Instrumenting a method body is also possible.
+<p>
+Methods are represented by <code>CtMethod</code> objects.
+<code>CtMethod</code> provides several methods for modifying
+the definition of the method. Note that if a method is inherited
+from a super class, then
+the same <code>CtMethod</code> object
+that represents the inherited method represents the method declared
+in that super class.
+A <code>CtMethod</code> object corresponds to every method declaration.
+
+<p>
+For example, if class <code>Point</code> declares method <code>move()</code>
+and a subclass <code>ColorPoint</code> of <code>Point</code> does
+not override <code>move()</code>, the two <code>move()</code> methods
+declared in <code>Point</code> and inherited in <code>ColorPoint</code>
+are represented by the identical <code>CtMethod</code> object.
+If the method definition represented by this
+<code>CtMethod</code> object is modified, the modification is
+reflected on both the methods.
+If you want to modify only the <code>move()</code> method in
+<code>ColorPoint</code>, you first have to add to <code>ColorPoint</code>
+a copy of the <code>CtMethod</code> object representing <code>move()</code>
+in <code>Point</code>. A copy of the the <code>CtMethod</code> object
+can be obtained by <code>CtNewMethod.copy()</code>.
+
+
<p><hr width="40%">
<ul>