[jboss-cvs] javassist/src/main/javassist/bytecode ...
Shigeru Chiba
chiba at is.titech.ac.jp
Wed Nov 22 21:49:04 EST 2006
User: chiba
Date: 06/11/22 21:49:04
Modified: src/main/javassist/bytecode Descriptor.java
Log:
added CtBehavior.getLongName()
Revision Changes Path
1.19 +63 -0 javassist/src/main/javassist/bytecode/Descriptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Descriptor.java
===================================================================
RCS file: /cvsroot/jboss/javassist/src/main/javassist/bytecode/Descriptor.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- Descriptor.java 11 Jan 2006 06:45:56 -0000 1.18
+++ Descriptor.java 23 Nov 2006 02:49:04 -0000 1.19
@@ -685,6 +685,69 @@
}
/**
+ * Returns a human-readable representation of the
+ * given descriptor. For example, <code>Ljava/lang/Object;</code>
+ * is converted into <code>java.lang.Object</code>.
+ * <code>(I[I)V</code> is converted into <code>(int, int[])</code>
+ * (the return type is ignored).
+ */
+ public static String toString(String desc) {
+ return PrettyPrinter.toString(desc);
+ }
+
+ static class PrettyPrinter {
+ static String toString(String desc) {
+ StringBuffer sbuf = new StringBuffer();
+ if (desc.charAt(0) == '(') {
+ int pos = 1;
+ sbuf.append('(');
+ while (desc.charAt(pos) != ')') {
+ if (pos > 1)
+ sbuf.append(',');
+
+ pos = readType(sbuf, pos, desc);
+ }
+
+ sbuf.append(')');
+ }
+ else
+ readType(sbuf, 0, desc);
+
+ return sbuf.toString();
+ }
+
+ static int readType(StringBuffer sbuf, int pos, String desc) {
+ char c = desc.charAt(pos);
+ int arrayDim = 0;
+ while (c == '[') {
+ arrayDim++;
+ c = desc.charAt(++pos);
+ }
+
+ if (c == 'L')
+ while (true) {
+ c = desc.charAt(++pos);
+ if (c == ';')
+ break;
+
+ if (c == '/')
+ c = '.';
+
+ sbuf.append(c);
+ }
+ else {
+ CtClass t = toPrimitiveClass(c);
+ sbuf.append(t.getName());
+ }
+
+ while (arrayDim-- > 0)
+ sbuf.append("[]");
+
+ return pos + 1;
+ }
+ }
+
+ /**
* An Iterator over a descriptor.
*/
public static class Iterator {
More information about the jboss-cvs-commits
mailing list