aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/javassist/CtClass.java32
-rw-r--r--src/main/javassist/CtClassType.java14
-rw-r--r--src/main/javassist/reflect/ClassMetaobject.java12
3 files changed, 44 insertions, 14 deletions
diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java
index c0962808..55f81b81 100644
--- a/src/main/javassist/CtClass.java
+++ b/src/main/javassist/CtClass.java
@@ -582,8 +582,8 @@ public abstract class CtClass {
/**
* Returns an array containing <code>CtField</code> objects
- * representing all the public fields of the class.
- * That array includes public fields inherited from the
+ * representing all the non-private fields of the class.
+ * That array includes non-private fields inherited from the
* superclasses.
*/
public CtField[] getFields() { return new CtField[0]; }
@@ -628,7 +628,7 @@ public abstract class CtClass {
/**
* Returns an array containing <code>CtConstructor</code> objects
- * representing all the public constructors of the class.
+ * representing all the non-private constructors of the class.
*/
public CtConstructor[] getConstructors() {
return new CtConstructor[0];
@@ -686,8 +686,8 @@ public abstract class CtClass {
/**
* Returns an array containing <code>CtMethod</code> objects
- * representing all the public methods of the class.
- * That array includes public methods inherited from the
+ * representing all the non-private methods of the class.
+ * That array includes pon-private methods inherited from the
* superclasses.
*/
public CtMethod[] getMethods() {
@@ -1043,12 +1043,13 @@ public abstract class CtClass {
* is on by default. Otherwise, it is off.
*
* @param stop disallow pruning if true. Otherwise, allow.
+ * @return the previous status of pruning. true if pruning is already stopped.
*
* @see #detach()
* @see #prune()
* @see ClassPool#doPruning
*/
- public void stopPruning(boolean stop) {}
+ public boolean stopPruning(boolean stop) { return true; }
/**
* Discards unnecessary attributes, in particuar,
@@ -1144,6 +1145,25 @@ public abstract class CtClass {
}
}
+ /**
+ * Writes a class file as <code>writeFile()</code> does although this
+ * method does not prune or freeze the class after writing the class
+ * file. Note that, once <code>writeFile()</code> or <code>toBytecode()</code>
+ * is called, it cannot be called again since the class is pruned and frozen.
+ * This method would be useful for debugging.
+ */
+ public void debugWriteFile() {
+ try {
+ boolean p = stopPruning(true);
+ writeFile();
+ defrost();
+ stopPruning(p);
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
static class DelayedFileOutputStream extends OutputStream {
private FileOutputStream file;
private String filename;
diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java
index 8d8e67d1..46fb268a 100644
--- a/src/main/javassist/CtClassType.java
+++ b/src/main/javassist/CtClassType.java
@@ -564,7 +564,7 @@ class CtClassType extends CtClass {
CtMember cf = ((CtClassType)cc).getFieldsCache();
while (cf != null) {
- if (Modifier.isPublic(cf.getModifiers()))
+ if (!Modifier.isPrivate(cf.getModifiers()))
alist.add(cf);
cf = cf.next;
@@ -680,7 +680,7 @@ class CtClassType extends CtClass {
int n = 0;
int i = cons.length;
while (--i >= 0)
- if (Modifier.isPublic(cons[i].getModifiers()))
+ if (!Modifier.isPrivate(cons[i].getModifiers()))
++n;
CtConstructor[] result = new CtConstructor[n];
@@ -688,7 +688,7 @@ class CtClassType extends CtClass {
i = cons.length;
while (--i >= 0) {
CtConstructor c = cons[i];
- if (Modifier.isPublic(c.getModifiers()))
+ if (!Modifier.isPrivate(c.getModifiers()))
result[n++] = c;
}
@@ -756,7 +756,7 @@ class CtClassType extends CtClass {
public CtMethod[] getMethods() {
HashMap h = new HashMap();
getMethods0(h, this);
- return (CtMethod[])h.values().toArray(new CtMethod[0]);
+ return (CtMethod[])h.values().toArray(new CtMethod[h.size()]);
}
private static void getMethods0(HashMap h, CtClass cc) {
@@ -778,7 +778,7 @@ class CtClassType extends CtClass {
if (cc instanceof CtClassType) {
CtMember cm = ((CtClassType)cc).getMethodsCache();
while (cm != null) {
- if (Modifier.isPublic(cm.getModifiers()))
+ if (!Modifier.isPrivate(cm.getModifiers()))
h.put(((CtMethod)cm).getStringRep(), cm);
cm = cm.next;
@@ -1120,8 +1120,10 @@ class CtClassType extends CtClass {
+ " was pruned.");
}
- public void stopPruning(boolean stop) {
+ public boolean stopPruning(boolean stop) {
+ boolean prev = !doPruning;
doPruning = !stop;
+ return prev;
}
private void modifyClassConstructor(ClassFile cf)
diff --git a/src/main/javassist/reflect/ClassMetaobject.java b/src/main/javassist/reflect/ClassMetaobject.java
index bfbc3f48..61328452 100644
--- a/src/main/javassist/reflect/ClassMetaobject.java
+++ b/src/main/javassist/reflect/ClassMetaobject.java
@@ -251,7 +251,8 @@ public class ClassMetaobject implements Serializable {
Class baseclass = getJavaClass();
Method[] allmethods = baseclass.getDeclaredMethods();
int n = allmethods.length;
- methods = new Method[n];
+ int[] index = new int[n];
+ int max = 0;
for (int i = 0; i < n; ++i) {
Method m = allmethods[i];
String mname = m.getName();
@@ -265,10 +266,17 @@ public class ClassMetaobject implements Serializable {
break;
}
- methods[k] = m;
+ index[i] = ++k;
+ if (k > max)
+ max = k;
}
}
+ methods = new Method[max];
+ for (int i = 0; i < n; ++i)
+ if (index[i] > 0)
+ methods[index[i] - 1] = allmethods[i];
+
return methods;
}