<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
public void fix(String name) {}
};
- cf.renameClass(cm);
+ cf.getRefClasses(cm);
return cm.values();
}
else
}
}
+ void getRefClasses(Map classnames) { renameClass(classnames); }
+
/**
* Returns a string representation of this object.
*/
/* 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) {}
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);
+ }
+ }
}
}
}
+ /**
+ * 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.
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.
}
}
+ void getRefClasses(Map classnames) { renameClass(classnames); }
+
/**
* Returns a string representation of this object.
*/
}
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 (;;) {
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;