< prev index next >

src/jdk.jextract/share/classes/com/sun/tools/jextract/Utils.java

Print this page

        

*** 119,208 **** public static String getName(Type type) { return LayoutUtils.getName(type); } - public static String ClassToDescriptor(Class<?> cls) { - if (cls.isArray()) { - return cls.getName(); - } - if (cls.isPrimitive()) { - switch (cls.getTypeName()) { - case "int": - return "I"; - case "long": - return "J"; - case "byte": - return "B"; - case "char": - return "C"; - case "float": - return "F"; - case "double": - return "D"; - case "short": - return "S"; - case "boolean": - return "Z"; - case "void": - return "V"; - } - } - // assuming reference - return "L" + cls.getName() + ";"; - } - - public static String DescriptorToBinaryName(String descriptor) { - final char[] ar = descriptor.trim().toCharArray(); - switch (ar[0]) { - case '(': - throw new IllegalArgumentException("Method descriptor is not allowed"); - case 'B': - return "byte"; - case 'C': - return "char"; - case 'D': - return "double"; - case 'F': - return "float"; - case 'I': - return "int"; - case 'J': - return "long"; - case 'S': - return "short"; - case 'Z': - return "boolean"; - } - - StringBuilder sb = new StringBuilder(); - if (ar[0] == 'L') { - for (int i = 1; i < ar.length && ar[i] != ';'; i++) { - if (ar[i] == '/') { - sb.append('.'); - } - if (!Character.isJavaIdentifierPart(ar[i])) { - throw new IllegalArgumentException("Malformed descriptor"); - } - sb.append(ar[i]); - } - return sb.toString(); - } - - if (ar[0] == '[') { - int depth = 1; - while (ar[depth] == '[') depth++; - sb.append(DescriptorToBinaryName(descriptor.substring(depth))); - for (int i = 0; i < depth; i++) { - sb.append("[]"); - } - return sb.toString(); - } - - throw new IllegalArgumentException("Malformed descriptor"); - } - public static Layout getLayout(Type type) { return LayoutUtils.getLayout(type); } public static Function getFunction(Type type) { --- 119,128 ----
< prev index next >