diff options
-rw-r--r-- | Readme.html | 2 | ||||
-rw-r--r-- | src/main/javassist/CtClass.java | 2 | ||||
-rw-r--r-- | src/main/javassist/bytecode/AnnotationsAttribute.java | 2 | ||||
-rw-r--r-- | src/main/javassist/bytecode/AttributeInfo.java | 15 | ||||
-rw-r--r-- | src/main/javassist/bytecode/ClassFile.java | 27 | ||||
-rw-r--r-- | src/main/javassist/bytecode/CodeAttribute.java | 4 | ||||
-rw-r--r-- | src/main/javassist/bytecode/ParameterAnnotationsAttribute.java | 2 | ||||
-rw-r--r-- | src/main/javassist/bytecode/SignatureAttribute.java | 57 |
8 files changed, 63 insertions, 48 deletions
diff --git a/Readme.html b/Readme.html index 87b9e634..8c7d0039 100644 --- a/Readme.html +++ b/Readme.html @@ -284,7 +284,7 @@ see javassist.Dump. <p>-version 3.14 <ul> - <li>JIRA JASSIST-130, 131, 132. + <li>JIRA JASSIST-128, 129, 130, 131, 132. </ul> <p>-version 3.13 on July 19, 2010 diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index c3d41760..9742de44 100644 --- a/src/main/javassist/CtClass.java +++ b/src/main/javassist/CtClass.java @@ -428,7 +428,7 @@ public abstract class CtClass { public void fix(String name) {} }; - cf.renameClass(cm); + cf.getRefClasses(cm); return cm.values(); } else diff --git a/src/main/javassist/bytecode/AnnotationsAttribute.java b/src/main/javassist/bytecode/AnnotationsAttribute.java index 7e53ce02..0d2ac099 100644 --- a/src/main/javassist/bytecode/AnnotationsAttribute.java +++ b/src/main/javassist/bytecode/AnnotationsAttribute.java @@ -285,6 +285,8 @@ public class AnnotationsAttribute extends AttributeInfo { } } + void getRefClasses(Map classnames) { renameClass(classnames); } + /** * Returns a string representation of this object. */ diff --git a/src/main/javassist/bytecode/AttributeInfo.java b/src/main/javassist/bytecode/AttributeInfo.java index 29c950ac..c5da7e1a 100644 --- a/src/main/javassist/bytecode/AttributeInfo.java +++ b/src/main/javassist/bytecode/AttributeInfo.java @@ -251,8 +251,9 @@ public class AttributeInfo { /* The following two methods are used to implement * ClassFile.renameClass(). - * Only CodeAttribute, LocalVariableAttribute, and - * AnnotationsAttribute override these methods. + * Only CodeAttribute, LocalVariableAttribute, + * AnnotationsAttribute, and SignatureAttribute + * override these methods. */ void renameClass(String oldname, String newname) {} void renameClass(Map classnames) {} @@ -272,4 +273,14 @@ public class AttributeInfo { ai.renameClass(classnames); } } + + void getRefClasses(Map classnames) {} + + static void getRefClasses(List attributes, Map classnames) { + Iterator iterator = attributes.iterator(); + while (iterator.hasNext()) { + AttributeInfo ai = (AttributeInfo)iterator.next(); + ai.getRefClasses(classnames); + } + } } diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java index 7c0662c3..d07d1088 100644 --- a/src/main/javassist/bytecode/ClassFile.java +++ b/src/main/javassist/bytecode/ClassFile.java @@ -466,6 +466,33 @@ public final class ClassFile { } /** + * Internal-use only. + * <code>CtClass.getRefClasses()</code> calls this method. + */ + public final void getRefClasses(Map classnames) { + constPool.renameClass(classnames); + + AttributeInfo.getRefClasses(attributes, classnames); + ArrayList list = methods; + int n = list.size(); + for (int i = 0; i < n; ++i) { + MethodInfo minfo = (MethodInfo)list.get(i); + String desc = minfo.getDescriptor(); + Descriptor.rename(desc, classnames); + AttributeInfo.getRefClasses(minfo.getAttributes(), classnames); + } + + list = fields; + n = list.size(); + for (int i = 0; i < n; ++i) { + FieldInfo finfo = (FieldInfo)list.get(i); + String desc = finfo.getDescriptor(); + Descriptor.rename(desc, classnames); + AttributeInfo.getRefClasses(finfo.getAttributes(), classnames); + } + } + + /** * Returns the names of the interfaces implemented by the class. * The returned array is read only. */ diff --git a/src/main/javassist/bytecode/CodeAttribute.java b/src/main/javassist/bytecode/CodeAttribute.java index 4705d2bb..99dca1d6 100644 --- a/src/main/javassist/bytecode/CodeAttribute.java +++ b/src/main/javassist/bytecode/CodeAttribute.java @@ -200,6 +200,10 @@ public class CodeAttribute extends AttributeInfo implements Opcode { AttributeInfo.renameClass(attributes, classnames); } + void getRefClasses(Map classnames) { + AttributeInfo.getRefClasses(attributes, classnames); + } + /** * Returns the name of the class declaring the method including * this code attribute. diff --git a/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java b/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java index 66386429..246afc1c 100644 --- a/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java +++ b/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java @@ -186,6 +186,8 @@ public class ParameterAnnotationsAttribute extends AttributeInfo { } } + void getRefClasses(Map classnames) { renameClass(classnames); } + /** * Returns a string representation of this object. */ diff --git a/src/main/javassist/bytecode/SignatureAttribute.java b/src/main/javassist/bytecode/SignatureAttribute.java index 267098f8..958e93f6 100644 --- a/src/main/javassist/bytecode/SignatureAttribute.java +++ b/src/main/javassist/bytecode/SignatureAttribute.java @@ -96,54 +96,16 @@ public class SignatureAttribute extends AttributeInfo { } static String renameClass(String desc, String oldname, String newname) { - if (desc.indexOf(oldname) < 0) - return desc; - - StringBuffer newdesc = new StringBuffer(); - int head = 0; - int i = 0; - for (;;) { - int j = desc.indexOf('L', i); - if (j < 0) - break; - - int k = j; - int p = 0; - char c; - boolean match = true; - try { - int len = oldname.length(); - while (isNamePart(c = desc.charAt(++k))) - if (p >= len || c != oldname.charAt(p++)) - match = false; - } - catch (IndexOutOfBoundsException e) { break; } - i = k + 1; - if (match && p == oldname.length()) { - newdesc.append(desc.substring(head, j)); - newdesc.append('L'); - newdesc.append(newname); - newdesc.append(c); - head = i; - } - } - - if (head == 0) - return desc; - else { - int len = desc.length(); - if (head < len) - newdesc.append(desc.substring(head, len)); - - return newdesc.toString(); - } + Map map = new java.util.HashMap(); + map.put(oldname, newname); + return renameClass(desc, map); } static String renameClass(String desc, Map map) { if (map == null) return desc; - StringBuffer newdesc = new StringBuffer(); + StringBuilder newdesc = new StringBuilder(); int head = 0; int i = 0; for (;;) { @@ -151,12 +113,19 @@ public class SignatureAttribute extends AttributeInfo { if (j < 0) break; - StringBuffer nameBuf = new StringBuffer(); + StringBuilder nameBuf = new StringBuilder(); int k = j; char c; try { - while (isNamePart(c = desc.charAt(++k))) + while ((c = desc.charAt(++k)) != ';') { nameBuf.append(c); + if (c == '<') { + while ((c = desc.charAt(++k)) != '>') + nameBuf.append(c); + + nameBuf.append(c); + } + } } catch (IndexOutOfBoundsException e) { break; } i = k + 1; |