1 11 package org.eclipse.jdt.internal.debug.core.model; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 import org.eclipse.debug.core.DebugEvent; 16 import org.eclipse.debug.core.DebugException; 17 import org.eclipse.debug.core.model.IValue; 18 import org.eclipse.jdt.debug.core.IJavaFieldVariable; 19 import org.eclipse.jdt.debug.core.IJavaObject; 20 import org.eclipse.jdt.debug.core.IJavaReferenceType; 21 import org.eclipse.jdt.debug.core.IJavaType; 22 import com.sun.jdi.ClassNotLoadedException; 23 import com.sun.jdi.ClassType; 24 import com.sun.jdi.Field; 25 import com.sun.jdi.InterfaceType; 26 import com.sun.jdi.InvalidTypeException; 27 import com.sun.jdi.ObjectReference; 28 import com.sun.jdi.ReferenceType; 29 import com.sun.jdi.Type; 30 import com.sun.jdi.Value; 31 32 35 public class JDIFieldVariable extends JDIModificationVariable implements IJavaFieldVariable { 36 39 private Field fField; 40 44 private ObjectReference fObject; 45 48 private ReferenceType fType; 49 50 53 public JDIFieldVariable(JDIDebugTarget target, Field field, ObjectReference objectRef) { 54 super(target); 55 fField= field; 56 if (!field.isStatic()) { 57 fObject= objectRef; 58 } 59 fType= (ReferenceType)objectRef.type(); 60 } 61 62 65 public JDIFieldVariable(JDIDebugTarget target, Field field, ReferenceType refType) { 66 super(target); 67 fField= field; 68 fType= refType; 69 } 70 71 74 protected Value retrieveValue() { 75 if (getField().isStatic()) { 76 return (getField().declaringType().getValue(getField())); 77 } 78 return getObjectReference().getValue(getField()); 79 } 80 81 84 public IJavaType getDeclaringType() { 85 return JDIType.createType((JDIDebugTarget)getDebugTarget(), fField.declaringType()); 86 } 87 88 91 public String getName() throws DebugException { 92 try { 93 return getField().name(); 94 } catch (RuntimeException e) { 95 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIFieldVariable_exception_retrieving_field_name, new String [] {e.toString()}), e); 96 return null; 99 } 100 } 101 102 protected void setJDIValue(Value value) throws DebugException { 103 try { 104 if (isStatic()) { 105 ReferenceType declaringType = getField().declaringType(); 106 if (declaringType instanceof InterfaceType) { 107 requestFailed(JDIDebugModelMessages.JDIFieldVariable_0, null); 108 } 109 ((ClassType)declaringType).setValue(getField(), value); 110 } else { 111 getObjectReference().setValue(getField(), value); 112 } 113 fireChangeEvent(DebugEvent.CONTENT); 114 } catch (ClassNotLoadedException e) { 115 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIFieldVariable_exception_modifying_value, new String [] {e.toString()}), e); 116 } catch (InvalidTypeException e) { 117 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIFieldVariable_exception_modifying_value, new String [] {e.toString()}), e); 118 } catch (RuntimeException e) { 119 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIFieldVariable_exception_modifying_value, new String [] {e.toString()}), e); 120 } 121 122 } 123 124 127 public boolean isVolatile() { 128 return getField().isVolatile(); 129 } 130 131 134 public boolean isTransient() { 135 return getField().isTransient(); 136 } 137 138 141 public boolean isSynthetic() { 142 return getField().isSynthetic(); 143 } 144 145 148 public boolean isPublic() { 149 return getField().isPublic(); 150 } 151 152 155 public boolean isPrivate() { 156 return getField().isPrivate(); 157 } 158 159 162 public boolean isProtected() { 163 return getField().isProtected(); 164 } 165 166 169 public boolean isPackagePrivate() { 170 return getField().isPackagePrivate(); 171 } 172 173 176 public boolean isStatic() { 177 return getField().isStatic(); 178 } 179 180 183 public boolean isFinal() { 184 return getField().isFinal(); 185 } 186 187 190 public String getReferenceTypeName() throws DebugException { 191 String genericSignature= getField().genericSignature(); 192 if (genericSignature != null) { 193 return JDIReferenceType.getTypeName(genericSignature); 194 } 195 Type underlyingType= getUnderlyingType(); 196 if (underlyingType instanceof ReferenceType) { 197 return JDIReferenceType.getGenericName((ReferenceType)underlyingType); 198 } 199 return getField().typeName(); 200 } 201 202 205 public String getSignature() throws DebugException { 206 try { 207 return getField().signature(); 208 } catch (RuntimeException e) { 209 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIFieldVariable_exception_retrieving_field_signature, new String [] {e.toString()}), e); 210 return null; 213 } 214 } 215 216 219 public String getGenericSignature() throws DebugException { 220 try { 221 String genericSignature= fField.genericSignature(); 222 if (genericSignature != null) { 223 return genericSignature; 224 } 225 return fField.signature(); 226 } catch (RuntimeException e) { 227 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIFieldVariable_exception_retrieving_field_signature, new String [] {e.toString()}), e); 228 return null; 231 } 232 } 233 234 public Field getField() { 235 return fField; 236 } 237 238 public ObjectReference getObjectReference() { 239 return fObject; 240 } 241 242 public ReferenceType getReferenceType() { 243 return fType; 244 } 245 246 public boolean supportsValueModification() { 247 if (getField().declaringType()instanceof InterfaceType) { 248 return false; 249 } 250 return super.supportsValueModification(); 251 } 252 253 256 public String toString() { 257 return getField().toString(); 258 } 259 260 263 public void setValue(IValue v) throws DebugException { 264 if (verifyValue(v)) { 265 setJDIValue(((JDIValue)v).getUnderlyingValue()); 266 } 267 } 268 269 272 protected Type getUnderlyingType() throws DebugException { 273 try { 274 return getField().type(); 275 } catch (ClassNotLoadedException e) { 276 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIFieldVariable_exception_while_retrieving_type_of_field, new String []{e.toString()}), e); 277 } catch (RuntimeException e) { 278 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIFieldVariable_exception_while_retrieving_type_of_field, new String []{e.toString()}), e); 279 } 280 return null; 283 } 284 285 288 public boolean equals(Object o) { 289 if (o instanceof JDIFieldVariable) { 290 JDIFieldVariable f = (JDIFieldVariable)o; 291 if (fObject != null) { 292 return fObject.equals(f.fObject) && f.fField.equals(fField); 293 } 294 return f.fField.equals(fField); 295 } 296 return false; 297 } 298 299 302 public int hashCode() { 303 if (fObject != null) { 304 return fField.hashCode() + fObject.hashCode(); 305 } 306 return fField.hashCode(); 307 } 308 309 312 public IJavaObject getReceiver() { 313 ObjectReference objectReference= getObjectReference(); 314 if (objectReference == null) { 315 return null; 316 } 317 return (IJavaObject)JDIValue.createValue(getJavaDebugTarget(), objectReference); 318 } 319 320 public IJavaReferenceType getReceivingType() { 321 return (IJavaReferenceType)JDIType.createType(getJavaDebugTarget(), getReferenceType()); 322 } 323 324 } 325 326 | Popular Tags |