Class.getName() return arrays in the form "[[[<et>", where et, the element type can be one of ZBCDFIJS or L<classname>;. It is converted into forms that can be understood by javac. @param type the type to convert @return the equivalent type in Java sources
(String type)
| 978 | * @return the equivalent type in Java sources |
| 979 | */ |
| 980 | public static String toJavaSourceType(String type) { |
| 981 | |
| 982 | if (type.charAt(0) != '[') { |
| 983 | return type; |
| 984 | } |
| 985 | |
| 986 | int dims = 1; |
| 987 | String t = null; |
| 988 | for (int i = 1; i < type.length(); i++) { |
| 989 | if (type.charAt(i) == '[') { |
| 990 | dims++; |
| 991 | } else { |
| 992 | t = switch (type.charAt(i)) { |
| 993 | case 'Z' -> "boolean"; |
| 994 | case 'B' -> "byte"; |
| 995 | case 'C' -> "char"; |
| 996 | case 'D' -> "double"; |
| 997 | case 'F' -> "float"; |
| 998 | case 'I' -> "int"; |
| 999 | case 'J' -> "long"; |
| 1000 | case 'S' -> "short"; |
| 1001 | case 'L' -> type.substring(i + 1, type.indexOf(';')); |
| 1002 | default -> null; |
| 1003 | }; |
| 1004 | break; |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | if (t == null) { |
| 1009 | // Should never happen |
| 1010 | throw new IllegalArgumentException(Localizer.getMessage("jsp.error.unable.getType", type)); |
| 1011 | } |
| 1012 | |
| 1013 | StringBuilder resultType = new StringBuilder(t); |
| 1014 | for (; dims > 0; dims--) { |
| 1015 | resultType.append("[]"); |
| 1016 | } |
| 1017 | return resultType.toString(); |
| 1018 | } |
| 1019 | } |