ByteCodeToJavaScript { private static String findMethodName(MethodData m, StringBuilder cnt) { StringBuilder name = new StringBuilder(); if ("<init>".equals(m.getName())) { name.append("cons"); } else if ("<clinit>".equals(m.getName())) { name.append("class"); } else { name.append(mangleMethodName(m.getName())); } countArgs(m.getInternalSig(), new char[1], name, cnt); return name.toString(); } protected  ByteCodeToJavaScript(final Appendable out); String compile(InputStream classFile);  }
@Test public void findMethodNameManglesObjectsCorrectly() { StringBuilder cnt = new StringBuilder(); char[] returnType = { 'V' }; String ret = ByteCodeToJavaScript.findMethodName(new String[] { "StringTest", "replace", "(Ljava/lang/String;CC)Ljava/lang/String;" }, cnt, returnType); assertEquals(cnt.toString(), "000", "No doubles or longs"); assertTrue(returnType[0] != 'V', "Returns string"); assertEquals(ret, "replace__Ljava_lang_String_2Ljava_lang_String_2CC"); }
@Test public void manglingArrays() { StringBuilder cnt = new StringBuilder(); char[] returnType = { 'V' }; String ret = ByteCodeToJavaScript.findMethodName(new String[] { "VMinVM", "toJavaScript", "([B)Ljava/lang/String;" }, cnt, returnType); assertEquals(cnt.toString(), "0", "No doubles or longs"); assertTrue(returnType[0] != 'V', "Returns string"); assertEquals(ret, "toJavaScript__Ljava_lang_String_2_3B"); }