diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2006-11-23 02:49:04 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2006-11-23 02:49:04 +0000 |
commit | 43a08a3a82916abdddd870752823c13bbb91ed0e (patch) | |
tree | 8948983d5ba5c48350617f573686944e50b7b1eb /src/main/javassist/bytecode/Descriptor.java | |
parent | 4f6352718e35fae2ad15745e16c05768882a17f9 (diff) | |
download | javassist-43a08a3a82916abdddd870752823c13bbb91ed0e.tar.gz javassist-43a08a3a82916abdddd870752823c13bbb91ed0e.zip |
added CtBehavior.getLongName()
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@336 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/bytecode/Descriptor.java')
-rw-r--r-- | src/main/javassist/bytecode/Descriptor.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/javassist/bytecode/Descriptor.java b/src/main/javassist/bytecode/Descriptor.java index b88fc339..f7185ab7 100644 --- a/src/main/javassist/bytecode/Descriptor.java +++ b/src/main/javassist/bytecode/Descriptor.java @@ -685,6 +685,69 @@ public class Descriptor { } /** + * 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 { |