PrettyPrinter { public static String typeDescriptor(String typeDescriptor) { int arrayLevels = 0; StringBuilder sb = new StringBuilder(); int i = 0; for (; i < typeDescriptor.length(); i++) { char c = typeDescriptor.charAt(i); switch (c) { case '[': arrayLevels++; break; case 'L': while (true) { i++; c = typeDescriptor.charAt(i); if (c == ';') { break; } if (c == '/') { c = '.'; } sb.append(c); } break; case 'V': sb.append("void"); break; case 'I': sb.append("int"); break; case 'S': sb.append("short"); break; case 'Z': sb.append("long"); break; case 'B': sb.append("boolean"); break; case 'D': sb.append("double"); break; case 'F': sb.append("float"); break; default: return className(typeDescriptor); } } for (int j = 0; j < arrayLevels; j++) { sb.append("[]"); } return sb.toString(); }  static String className(String className); static String typeDescriptor(String typeDescriptor);  }
@Test public void testPrimitives() throws Exception { assertEquals("int", PrettyPrinter.typeDescriptor("I")); assertEquals("short", PrettyPrinter.typeDescriptor("S")); assertEquals("long", PrettyPrinter.typeDescriptor("Z")); assertEquals("double", PrettyPrinter.typeDescriptor("D")); assertEquals("float", PrettyPrinter.typeDescriptor("F")); assertEquals("boolean", PrettyPrinter.typeDescriptor("B")); assertEquals("void", PrettyPrinter.typeDescriptor("V")); }
@Test public void testPrimitiveArrays() throws Exception { assertEquals("int[]", PrettyPrinter.typeDescriptor("[I")); assertEquals("short[]", PrettyPrinter.typeDescriptor("[S")); }
@Test public void testClasses() throws Exception { assertEquals("com.spotify.Foo", PrettyPrinter.typeDescriptor("Lcom/spotify/Foo;")); }