git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@574 30ef5769-5b8d-40dd-aea6-55b5d6557bb3tags/rel_3_17_1_ga
@@ -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 |
@@ -428,7 +428,7 @@ public abstract class CtClass { | |||
public void fix(String name) {} | |||
}; | |||
cf.renameClass(cm); | |||
cf.getRefClasses(cm); | |||
return cm.values(); | |||
} | |||
else |
@@ -285,6 +285,8 @@ public class AnnotationsAttribute extends AttributeInfo { | |||
} | |||
} | |||
void getRefClasses(Map classnames) { renameClass(classnames); } | |||
/** | |||
* Returns a string representation of this object. | |||
*/ |
@@ -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); | |||
} | |||
} | |||
} |
@@ -465,6 +465,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. |
@@ -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. |
@@ -186,6 +186,8 @@ public class ParameterAnnotationsAttribute extends AttributeInfo { | |||
} | |||
} | |||
void getRefClasses(Map classnames) { renameClass(classnames); } | |||
/** | |||
* Returns a string representation of this object. | |||
*/ |
@@ -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; |