1 11 package org.eclipse.jdi.internal; 12 13 14 import java.io.ByteArrayOutputStream ; 15 import java.io.DataInputStream ; 16 import java.io.DataOutputStream ; 17 import java.io.IOException ; 18 import java.util.Collections ; 19 import java.util.HashMap ; 20 import java.util.List ; 21 import java.util.Map ; 22 23 import org.eclipse.jdi.internal.jdwp.JdwpArrayID; 24 import org.eclipse.jdi.internal.jdwp.JdwpCommandPacket; 25 import org.eclipse.jdi.internal.jdwp.JdwpID; 26 import org.eclipse.jdi.internal.jdwp.JdwpObjectID; 27 import org.eclipse.jdi.internal.jdwp.JdwpReplyPacket; 28 29 import com.sun.jdi.AbsentInformationException; 30 import com.sun.jdi.ArrayReference; 31 import com.sun.jdi.ArrayType; 32 import com.sun.jdi.ClassNotLoadedException; 33 import com.sun.jdi.Field; 34 import com.sun.jdi.Type; 35 import com.sun.jdi.Value; 36 37 43 public class ArrayTypeImpl extends ReferenceTypeImpl implements ArrayType { 44 45 public static final byte typeTag = JdwpID.TYPE_TAG_ARRAY; 46 47 private Type fComponentType; 48 49 private String fComponentTypeName; 50 51 54 public ArrayTypeImpl(VirtualMachineImpl vmImpl, JdwpArrayID arrayID) { 55 super("ArrayType", vmImpl, arrayID); } 57 58 61 public ArrayTypeImpl(VirtualMachineImpl vmImpl, JdwpArrayID arrayID, String signature, String genericSignature) { 62 super("ArrayType", vmImpl, arrayID, signature, genericSignature); } 64 65 68 public byte typeTag() { 69 return typeTag; 70 } 71 72 75 public Value createNullValue() { 76 return new ArrayReferenceImpl(virtualMachineImpl(), new JdwpObjectID(virtualMachineImpl())); 77 } 78 79 82 public String componentSignature() { 83 return signature().substring(1); 84 } 85 86 89 public Type componentType() throws ClassNotLoadedException { 90 if (fComponentType == null) { 91 fComponentType = TypeImpl.create(virtualMachineImpl(), componentSignature(), classLoader()); 92 } 93 return fComponentType; 94 } 95 96 99 public String componentTypeName() { 100 if (fComponentTypeName == null) { 101 fComponentTypeName = signatureToName(componentSignature()); 102 } 103 return fComponentTypeName; 104 } 105 106 109 public ArrayReference newInstance(int length) { 110 initJdwpRequest(); 112 try { 113 ByteArrayOutputStream outBytes = new ByteArrayOutputStream (); 114 DataOutputStream outData = new DataOutputStream (outBytes); 115 write(this, outData); 116 writeInt(length, "length", outData); 118 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.AT_NEW_INSTANCE, outBytes); 119 defaultReplyErrorHandler(replyPacket.errorCode()); 120 121 DataInputStream replyData = replyPacket.dataInStream(); 122 ArrayReferenceImpl arrayRef = (ArrayReferenceImpl)ObjectReferenceImpl.readObjectRefWithTag(this, replyData); 123 return arrayRef; 124 } catch (IOException e) { 125 defaultIOExceptionHandler(e); 126 return null; 127 } finally { 128 handledJdwpRequest(); 129 } 130 } 131 132 135 public List locationsOfLine(int line) { 136 return Collections.EMPTY_LIST; 138 } 139 140 143 public static ArrayTypeImpl read(MirrorImpl target, DataInputStream in) throws IOException { 144 VirtualMachineImpl vmImpl = target.virtualMachineImpl(); 145 JdwpArrayID ID = new JdwpArrayID(vmImpl); 146 ID.read(in); 147 if (target.fVerboseWriter != null) 148 target.fVerboseWriter.println("arrayType", ID.value()); 150 if (ID.isNull()) 151 return null; 152 153 ArrayTypeImpl mirror = (ArrayTypeImpl)vmImpl.getCachedMirror(ID); 154 if (mirror == null) { 155 mirror = new ArrayTypeImpl(vmImpl, ID); 156 vmImpl.addCachedMirror(mirror); 157 } 158 return mirror; 159 } 160 161 164 public int modifiers() { 165 return MODIFIER_ACC_PUBLIC | MODIFIER_ACC_FINAL; 166 } 167 168 171 public List fields() { 172 return Collections.EMPTY_LIST; 173 } 174 175 178 public List methods() { 179 return Collections.EMPTY_LIST; 180 } 181 182 185 public Map getValues(List fields) { 186 if (fields.isEmpty()) { 187 return new HashMap (); 188 } 189 190 throw new IllegalArgumentException (JDIMessages.ArrayTypeImpl_getValues_not_allowed_on_array_1); 191 } 192 193 196 public List nestedTypes() { 197 return Collections.EMPTY_LIST; 198 } 199 200 203 protected int status() { 204 return ReferenceTypeImpl.JDWP_CLASS_STATUS_INITIALIZED | ReferenceTypeImpl.JDWP_CLASS_STATUS_PREPARED | ReferenceTypeImpl.JDWP_CLASS_STATUS_VERIFIED; 205 } 206 207 210 public static ArrayTypeImpl readWithSignature(MirrorImpl target, boolean withGenericSignature, DataInputStream in) throws IOException { 211 VirtualMachineImpl vmImpl = target.virtualMachineImpl(); 212 JdwpArrayID ID = new JdwpArrayID(vmImpl); 213 ID.read(in); 214 if (target.fVerboseWriter != null) 215 target.fVerboseWriter.println("arrayType", ID.value()); 217 String signature = target.readString("signature", in); String genericSignature= null; 219 if (withGenericSignature) { 220 genericSignature= target.readString("generic signature", in); } 222 if (ID.isNull()) 223 return null; 224 225 ArrayTypeImpl mirror = (ArrayTypeImpl)vmImpl.getCachedMirror(ID); 226 if (mirror == null) { 227 mirror = new ArrayTypeImpl(vmImpl, ID); 228 vmImpl.addCachedMirror(mirror); 229 } 230 mirror.setSignature(signature); 231 mirror.setGenericSignature(genericSignature); 232 return mirror; 233 } 234 235 238 public List allLineLocations() { 239 return Collections.EMPTY_LIST; 241 } 242 245 public List allMethods() { 246 return Collections.EMPTY_LIST; 247 } 248 251 public List allFields() { 252 return Collections.EMPTY_LIST; 253 } 254 255 258 public String sourceName() throws AbsentInformationException { 259 throw new AbsentInformationException(JDIMessages.ArrayTypeImpl_No_source_name_for_Arrays_1); 260 } 261 264 public List visibleFields() { 265 return Collections.EMPTY_LIST; 266 } 267 268 271 public List visibleMethods() { 272 return Collections.EMPTY_LIST; 273 } 274 277 public Field fieldByName(String arg1) { 278 return null; 279 } 280 283 public List methodsByName(String arg1) { 284 return Collections.EMPTY_LIST; 285 } 286 287 290 public List methodsByName(String arg1, String arg2) { 291 return Collections.EMPTY_LIST; 292 } 293 } 294 | Popular Tags |