1 11 package org.eclipse.jdi.internal; 12 13 14 import com.sun.jdi.ClassLoaderReference; 15 import com.sun.jdi.ClassNotLoadedException; 16 import com.sun.jdi.ClassNotPreparedException; 17 import com.sun.jdi.Type; 18 import com.sun.jdi.Value; 19 20 26 public abstract class TypeImpl extends AccessibleImpl implements Type { 27 28 protected String fName = null; 29 30 protected String fSignature = null; 31 32 35 protected TypeImpl(String description, VirtualMachineImpl vmImpl) { 36 super(description, vmImpl); 37 } 38 39 42 protected TypeImpl(String description, VirtualMachineImpl vmImpl, String name, String signature) { 43 super(description, vmImpl); 44 setName(name); 45 setSignature(signature); 46 } 47 48 53 public static TypeImpl create(VirtualMachineImpl vmImpl, String signature, ClassLoaderReference classLoader) throws ClassNotLoadedException { 54 if (isVoidSignature(signature)) 56 return new VoidTypeImpl(vmImpl); 57 58 if (isPrimitiveSignature(signature)) 60 return PrimitiveTypeImpl.create(vmImpl, signature); 61 62 return ReferenceTypeImpl.create(vmImpl, signature, classLoader); 65 } 66 67 70 public void setName(String name) { 71 fName = name; 72 } 73 74 77 public void setSignature(String signature) { 78 fSignature = signature; 79 } 80 81 84 public String toString() { 85 try { 86 return name(); 87 } catch (ClassNotPreparedException e) { 88 return JDIMessages.TypeImpl__Unloaded_Type__1; 89 } catch (Exception e) { 90 return fDescription; 91 } 92 } 93 94 97 public abstract Value createNullValue(); 98 99 102 public String name() { 103 return fName; 104 } 105 106 109 public String signature() { 110 return fSignature; 111 } 112 113 116 public abstract int modifiers(); 117 118 121 public static String classNameToSignature(String qualifiedName) { 122 129 StringBuffer signature= new StringBuffer (); 130 131 int firstBrace= qualifiedName.indexOf('['); 132 if (firstBrace < 0) { 133 signature.append('L'); 135 signature.append(qualifiedName.replace('.','/')); 136 signature.append(';'); 137 return signature.toString(); 138 } 139 140 int index= 0; 141 while ((index= (qualifiedName.indexOf('[', index) + 1)) > 0) { 142 signature.append('['); 143 } 144 145 String name= qualifiedName.substring(0, firstBrace); 146 switch (name.charAt(0)) { 147 case 'b': 149 if (name.equals("byte")) { signature.append('B'); 151 return signature.toString(); 152 } else if (name.equals("boolean")) { signature.append('Z'); 154 return signature.toString(); 155 } 156 break; 157 case 'i': 158 if (name.equals("int")) { signature.append('I'); 160 return signature.toString(); 161 } 162 break; 163 case 'd': 164 if (name.equals("double")) { signature.append('D'); 166 return signature.toString(); 167 } 168 break; 169 case 's': 170 if (name.equals("short")) { signature.append('S'); 172 return signature.toString(); 173 } 174 break; 175 case 'c': 176 if (name.equals("char")) { signature.append('C'); 178 return signature.toString(); 179 } 180 break; 181 case 'l': 182 if (name.equals("long")) { signature.append('J'); 184 return signature.toString(); 185 } 186 break; 187 case 'f': 188 if (name.equals("float")) { signature.append('F'); 190 return signature.toString(); 191 } 192 break; 193 } 194 signature.append('L'); 196 signature.append(name.replace('.','/')); 197 signature.append(';'); 198 return signature.toString(); 199 } 200 201 202 205 public static String classSignatureToName(String signature) { 206 return signature.substring(1, signature.length() - 1).replace('/','.'); 208 } 209 210 213 public static String arraySignatureToName(String signature) { 214 if (signature.indexOf('[') < 0) { 216 return signature; 217 } 218 StringBuffer name= new StringBuffer (); 219 String type= signature.substring(signature.lastIndexOf('[') + 1); 220 if (type.length() == 1 && isPrimitiveSignature(type)) { 221 name.append(getPrimitiveSignatureToName(type.charAt(0))); 222 } else { 223 name.append(classSignatureToName(type)); 224 } 225 int index= 0; 226 while ((index= (signature.indexOf('[', index) + 1)) > 0) { 227 name.append('[').append(']'); 228 } 229 return signatureToName(signature.substring(1)) + "[]"; } 231 232 235 public static String signatureToName(String signature) { 236 String primitive= getPrimitiveSignatureToName(signature.charAt(0)); 238 if (primitive != null) { 239 return primitive; 240 } 241 switch (signature.charAt(0)) { 242 case 'V': 243 return "void"; case 'L': 245 return classSignatureToName(signature); 246 case '[': 247 return arraySignatureToName(signature); 248 case '(': 249 throw new InternalError (JDIMessages.TypeImpl_Can__t_convert_method_signature_to_name_2); 250 } 251 throw new InternalError (JDIMessages.TypeImpl_Invalid_signature____10 + signature + JDIMessages.TypeImpl___11); } 253 254 private static String getPrimitiveSignatureToName(char signature) { 255 switch (signature) { 256 case 'Z': 257 return "boolean"; case 'B': 259 return "byte"; case 'C': 261 return "char"; case 'S': 263 return "short"; case 'I': 265 return "int"; case 'J': 267 return "long"; case 'F': 269 return "float"; case 'D': 271 return "double"; default: 273 return null; 274 } 275 } 276 277 280 public static byte signatureToTag(String signature) { 281 switch (signature.charAt(0)) { 282 case 'Z': 283 return BooleanValueImpl.tag; 284 case 'B': 285 return ByteValueImpl.tag; 286 case 'C': 287 return CharValueImpl.tag; 288 case 'S': 289 return ShortValueImpl.tag; 290 case 'I': 291 return IntegerValueImpl.tag; 292 case 'J': 293 return LongValueImpl.tag; 294 case 'F': 295 return FloatValueImpl.tag; 296 case 'D': 297 return DoubleValueImpl.tag; 298 case 'V': 299 return VoidValueImpl.tag; 300 case 'L': 301 return ObjectReferenceImpl.tag; 302 case '[': 303 return ArrayReferenceImpl.tag; 304 case '(': 305 throw new InternalError (JDIMessages.TypeImpl_Can__t_covert_method_signature_to_tag___9 + signature); 306 } 307 throw new InternalError (JDIMessages.TypeImpl_Invalid_signature____10 + signature + JDIMessages.TypeImpl___11); } 309 310 313 public static boolean isPrimitiveSignature(String signature) { 314 switch (signature.charAt(0)) { 315 case 'Z': 316 case 'B': 317 case 'C': 318 case 'S': 319 case 'I': 320 case 'J': 321 case 'F': 322 case 'D': 323 return true; 324 } 325 return false; 326 } 327 328 331 public static boolean isVoidSignature(String signature) { 332 return (signature.charAt(0) == 'V'); 333 } 334 335 336 } 337
| Popular Tags
|