From: chiba Date: Mon, 16 May 2005 03:01:34 +0000 (+0000) Subject: some simple style changes X-Git-Tag: rel_3_17_1_ga~452 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d555274962db5f50c330c735a1b396376faa4891;p=javassist.git some simple style changes git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@169 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/src/main/javassist/bytecode/Descriptor.java b/src/main/javassist/bytecode/Descriptor.java index efd7eaec..a09f198b 100644 --- a/src/main/javassist/bytecode/Descriptor.java +++ b/src/main/javassist/bytecode/Descriptor.java @@ -58,30 +58,58 @@ public class Descriptor { } /** - * Converts to a Java class name from a descriptor + * Converts to a Java class name from a descriptor. + * + * @param descriptor type descriptor. */ public static String toClassName(String descriptor) { - if (descriptor.equals("V")) - return "void"; - else if (descriptor.equals("I")) - return "int"; - else if (descriptor.equals("B")) - return "byte"; - else if (descriptor.equals("J")) - return "long"; - else if (descriptor.equals("D")) - return "double"; - else if (descriptor.equals("F")) - return "float"; - else if (descriptor.equals("C")) - return "char"; - else if (descriptor.equals("S")) - return "short"; - else if (descriptor.equals("Z")) - return "boolean"; + int arrayDim = 0; + int i = 0; + char c = descriptor.charAt(0); + while (c == '[') { + ++arrayDim; + c = descriptor.charAt(++i); + } + + String name; + if (c == 'L') { + int i2 = descriptor.indexOf(';', i++); + name = descriptor.substring(i, i2).replace('/', '.'); + i = i2; + } + else if (c == 'V') + name = "void"; + else if (c == 'I') + name = "int"; + else if (c == 'B') + name = "byte"; + else if (c == 'J') + name = "long"; + else if (c == 'D') + name = "double"; + else if (c == 'F') + name = "float"; + else if (c == 'C') + name = "char"; + else if (c == 'S') + name = "short"; + else if (c == 'Z') + name = "boolean"; + else + throw new RuntimeException("bad descriptor: " + descriptor); + + if (i + 1 != descriptor.length()) + throw new RuntimeException("multiple descriptors?: " + descriptor); + + if (arrayDim == 0) + return name; else { - String newname = toJavaName(descriptor); - return newname.substring(1, newname.length() - 1); + StringBuffer sbuf = new StringBuffer(name); + do { + sbuf.append("[]"); + } while (--arrayDim > 0); + + return sbuf.toString(); } }