1 11 package org.eclipse.jdt.internal.debug.core.model; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 16 import org.eclipse.debug.core.DebugEvent; 17 import org.eclipse.debug.core.DebugException; 18 import org.eclipse.debug.core.model.IValue; 19 20 import com.sun.jdi.ArrayReference; 21 import com.sun.jdi.ArrayType; 22 import com.sun.jdi.ClassNotLoadedException; 23 import com.sun.jdi.InvalidTypeException; 24 import com.sun.jdi.ReferenceType; 25 import com.sun.jdi.Type; 26 import com.sun.jdi.Value; 27 28 31 32 public class JDIArrayEntryVariable extends JDIModificationVariable { 33 34 37 private int fIndex; 38 39 42 private ArrayReference fArray; 43 44 47 private String fReferenceTypeName= null; 48 49 52 public JDIArrayEntryVariable(JDIDebugTarget target, ArrayReference array, int index) { 53 super(target); 54 fArray= array; 55 fIndex= index; 56 } 57 58 61 protected Value retrieveValue() { 62 ArrayReference ar= getArrayReference(); 63 if (ar != null) { 64 return ar.getValue(getIndex()); 65 } 66 return null; 67 } 68 69 72 public String getName() { 73 return "[" + getIndex() + "]"; } 75 76 protected void setJDIValue(Value value) throws DebugException { 77 ArrayReference ar= getArrayReference(); 78 if (ar == null) { 79 requestFailed(JDIDebugModelMessages.JDIArrayEntryVariable_value_modification_failed, null); 80 } 81 try { 82 ar.setValue(getIndex(), value); 83 fireChangeEvent(DebugEvent.CONTENT); 84 } catch (ClassNotLoadedException e) { 85 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayEntryVariable_exception_modifying_variable_value, new String [] {e.toString()}), e); 86 } catch (InvalidTypeException e) { 87 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayEntryVariable_exception_modifying_variable_value, new String [] {e.toString()}), e); 88 } catch (RuntimeException e) { 89 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayEntryVariable_exception_modifying_variable_value, new String [] {e.toString()}), e); 90 } 91 92 } 93 94 protected ArrayReference getArrayReference() { 95 return fArray; 96 } 97 98 protected int getIndex() { 99 return fIndex; 100 } 101 102 105 public String getReferenceTypeName() throws DebugException { 106 try { 107 if (fReferenceTypeName == null) { 108 fReferenceTypeName= stripBrackets(JDIReferenceType.getGenericName(getArrayReference().referenceType())); 109 } 110 } catch (RuntimeException e) { 111 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayEntryVariable_exception_retrieving_reference_type, new String [] {e.toString()}), e); 112 return null; 115 } 116 return fReferenceTypeName; 117 } 118 119 123 protected String stripBrackets(String typeName) { 124 int lastLeft= typeName.lastIndexOf("[]"); if (lastLeft < 0) { 126 return typeName; 127 } 128 StringBuffer buffer= new StringBuffer (typeName); 129 buffer.replace(lastLeft, lastLeft + 2, ""); return buffer.toString(); 131 } 132 133 136 public String getSignature() throws DebugException { 137 try { 138 return ((ArrayType) getArrayReference().type()).componentSignature(); 139 } catch (RuntimeException e) { 140 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayEntryVariable_exception_retrieving_type_signature, new String [] {e.toString()}), e); 141 return null; 144 } 145 } 146 147 150 public String getGenericSignature() throws DebugException { 151 try { 152 ReferenceType referenceType= getArrayReference().referenceType(); 153 String genericSignature= referenceType.genericSignature(); 154 if (genericSignature != null) { 155 return genericSignature; 156 } 157 return referenceType.signature(); 158 } catch (RuntimeException e) { 159 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayEntryVariable_exception_retrieving_type_signature, new String [] {e.toString()}), e); 160 return null; 163 } 164 } 165 166 169 public void setValue(IValue v) throws DebugException { 170 if (verifyValue(v)) { 171 JDIValue value = (JDIValue)v; 172 setJDIValue(value.getUnderlyingValue()); 173 } 174 } 175 176 179 protected Type getUnderlyingType() throws DebugException { 180 try { 181 return ((ArrayType)getArrayReference().type()).componentType(); 182 } catch (ClassNotLoadedException e) { 183 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayEntryVariable_exception_while_retrieving_type_of_array_entry, new String []{e.toString()}), e); 184 } catch (RuntimeException e) { 185 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayEntryVariable_exception_while_retrieving_type_of_array_entry, new String []{e.toString()}), e); 186 } 187 return null; 190 } 191 194 public boolean equals(Object obj) { 195 if (obj instanceof JDIArrayEntryVariable) { 196 JDIArrayEntryVariable entry = (JDIArrayEntryVariable)obj; 197 return entry.getArrayReference().equals(getArrayReference()) && 198 entry.getIndex() == getIndex(); 199 } 200 return false; 201 } 202 203 206 public int hashCode() { 207 return getArrayReference().hashCode() + getIndex(); 208 } 209 210 } 211 212 | Popular Tags |