1 9 10 package org.jruby.util; 11 12 16 public class CodegenUtils { 17 public static final CodegenUtils instance = new CodegenUtils(); 18 19 22 public static String c(String p) { 23 return p.replace('/', '.'); 24 } 25 26 29 public static String p(Class n) { 30 return n.getName().replace('.','/'); 31 } 32 33 36 public static String ci(Class n) { 37 if (n.isArray()) { 38 n = n.getComponentType(); 39 if (n.isPrimitive()) { 40 if (n == Byte.TYPE) { 41 return "[B"; 42 } else if (n == Boolean.TYPE) { 43 return "[Z"; 44 } else if (n == Integer.TYPE) { 45 return "[I"; 46 } else if (n == Double.TYPE) { 47 return "[D"; 48 } else if (n == Long.TYPE) { 49 return "[J"; 50 } else { 51 throw new RuntimeException ("Unrecognized type in compiler: " + n.getName()); 52 } 53 } else { 54 return "[" + ci(n); 55 } 56 } else { 57 if (n.isPrimitive()) { 58 if (n == Byte.TYPE) { 59 return "B"; 60 } else if (n == Boolean.TYPE) { 61 return "Z"; 62 } else if (n == Integer.TYPE) { 63 return "I"; 64 } else if (n == Double.TYPE) { 65 return "D"; 66 } else if (n == Long.TYPE) { 67 return "J"; 68 } else if (n == Void.TYPE) { 69 return "V"; 70 } else { 71 throw new RuntimeException ("Unrecognized type in compiler: " + n.getName()); 72 } 73 } else { 74 return "L" + p(n) + ";"; 75 } 76 } 77 } 78 79 82 public static String sig(Class retval, Class [] params) { 83 StringBuffer signature = new StringBuffer ("("); 84 85 for (int i = 0; i < params.length; i++) { 86 signature.append(ci(params[i])); 87 } 88 89 signature.append(")").append(ci(retval)); 90 91 return signature.toString(); 92 } 93 94 97 public static String sig(Class retval) { 98 StringBuffer signature = new StringBuffer ("()"); 99 100 signature.append(ci(retval)); 101 102 return signature.toString(); 103 } 104 105 public static Class [] params() { 107 return new Class [0]; 108 } 109 public static Class [] params(Class a) { 110 return new Class [] {a}; 111 } 112 public static Class [] params(Class a, Class b) { 113 return new Class [] {a,b}; 114 } 115 public static Class [] params(Class a, Class b, Class c) { 116 return new Class [] {a,b,c}; 117 } 118 public static Class [] params(Class a, Class b, Class c, Class d) { 119 return new Class [] {a,b,c,d}; 120 } 121 public static Class [] params(Class a, Class b, Class c, Class d, Class e) { 122 return new Class [] {a,b,c,d,e}; 123 } 124 public static Class [] params(Class a, Class b, Class c, Class d, Class e, Class f) { 125 return new Class [] {a,b,c,d,e,f}; 126 } 127 128 } 129 | Popular Tags |