1 29 30 package com.caucho.bytecode; 31 32 import com.caucho.util.CharBuffer; 33 34 import java.lang.reflect.ParameterizedType ; 35 import java.lang.reflect.Type ; 36 37 40 public class JTypeWrapper implements JType { 41 private JClassLoader _loader; 42 43 private ParameterizedType _type; 44 45 public JTypeWrapper(JClassLoader loader, ParameterizedType type) 46 { 47 _loader = loader; 48 49 _type = type; 50 } 51 52 55 public String getName() 56 { 57 return ((Class ) _type.getRawType()).getName(); 58 } 59 60 63 public String getPrintName() 64 { 65 JType []typeArgs = getActualTypeArguments(); 66 67 if (typeArgs.length == 0) 68 return getRawClass().getPrintName(); 69 70 CharBuffer cb = new CharBuffer(); 71 cb.append(getRawClass().getPrintName()); 72 cb.append('<'); 73 for (int i = 0; i < typeArgs.length; i++) { 74 if (i != 0) 75 cb.append(','); 76 77 cb.append(typeArgs[i].getPrintName()); 78 } 79 80 cb.append('>'); 81 82 return cb.toString(); 83 } 84 85 88 public JType []getActualTypeArguments() 89 { 90 Type []rawArgs = _type.getActualTypeArguments(); 91 92 JType []args = new JType[rawArgs.length]; 93 for (int i = 0; i < args.length; i++) { 94 Type type = rawArgs[i]; 95 96 if (type instanceof Class ) 97 args[i] = _loader.forName(((Class ) type).getName()); 98 else if (type instanceof ParameterizedType ) 99 args[i] = new JTypeWrapper(_loader, (ParameterizedType ) type); 100 else { 101 args[i] = _loader.forName("java.lang.Object"); 102 } 105 } 106 107 return args; 108 } 109 110 113 public JClass getRawType() 114 { 115 return _loader.forName(((Class ) _type.getRawType()).getName()); 116 } 117 118 119 122 public boolean isPrimitive() 123 { 124 return getRawClass().isPrimitive(); 125 } 126 127 130 public boolean isPublic() 131 { 132 return getRawClass().isPublic(); 133 } 134 135 138 public boolean isAbstract() 139 { 140 return getRawClass().isAbstract(); 141 } 142 143 146 public boolean isFinal() 147 { 148 return getRawClass().isFinal(); 149 } 150 151 154 public boolean isInterface() 155 { 156 return getRawClass().isAbstract(); 157 } 158 159 162 public JClass getSuperClass() 163 { 164 return getRawClass().getSuperClass(); 165 } 166 167 170 public JClass []getInterfaces() 171 { 172 return getRawClass().getInterfaces(); 173 } 174 175 178 public boolean isArray() 179 { 180 return getRawClass().isArray(); 181 } 182 183 186 public JClass getComponentType() 187 { 188 return null; 189 } 190 191 194 public boolean isAssignableTo(Class cl) 195 { 196 return getRawClass().isAssignableTo(cl); 197 } 198 199 202 public boolean isAssignableFrom(Class cl) 203 { 204 return getRawClass().isAssignableFrom(cl); 205 } 206 207 210 public boolean isAssignableFrom(JClass cl) 211 { 212 return getRawClass().isAssignableFrom(cl); 213 } 214 215 218 public JMethod []getDeclaredMethods() 219 { 220 return getRawClass().getDeclaredMethods(); 221 } 222 223 226 public JMethod []getMethods() 227 { 228 return getRawClass().getMethods(); 229 } 230 231 234 public JMethod getMethod(String name, JClass []param) 235 { 236 return getRawClass().getMethod(name, param); 237 } 238 239 242 public JField []getDeclaredFields() 243 { 244 return getRawClass().getDeclaredFields(); 245 } 246 247 250 public JField []getFields() 251 { 252 return getRawClass().getFields(); 253 } 254 255 private JClass getRawClass() 256 { 257 return _loader.forName(((Class ) _type.getRawType()).getName()); 258 } 259 } 260 | Popular Tags |