aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2010-09-14 14:38:43 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2010-09-14 14:38:43 +0000
commit4b05c10a1e3591547e669d116538949c0cb3905f (patch)
tree8843334ad15199216862d0c5e217dd707302d81e /src/main/javassist
parent325084e1ad1d5de64953b5eb9bc8b064484b7f97 (diff)
downloadjavassist-4b05c10a1e3591547e669d116538949c0cb3905f.tar.gz
javassist-4b05c10a1e3591547e669d116538949c0cb3905f.zip
fixed JASSIST-128 and JASSIST-129
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@574 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist')
-rw-r--r--src/main/javassist/CtClass.java2
-rw-r--r--src/main/javassist/bytecode/AnnotationsAttribute.java2
-rw-r--r--src/main/javassist/bytecode/AttributeInfo.java15
-rw-r--r--src/main/javassist/bytecode/ClassFile.java27
-rw-r--r--src/main/javassist/bytecode/CodeAttribute.java4
-rw-r--r--src/main/javassist/bytecode/ParameterAnnotationsAttribute.java2
-rw-r--r--src/main/javassist/bytecode/SignatureAttribute.java57
7 files changed, 62 insertions, 47 deletions
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;