1 11 package org.eclipse.jdt.internal.debug.core.model; 12 13 14 import org.eclipse.debug.core.DebugException; 15 import org.eclipse.debug.core.model.IValue; 16 import org.eclipse.jdt.debug.core.IJavaModifiers; 17 import org.eclipse.jdt.debug.core.IJavaType; 18 import org.eclipse.jdt.debug.core.IJavaVariable; 19 20 import com.ibm.icu.text.MessageFormat; 21 import com.sun.jdi.Type; 22 import com.sun.jdi.Value; 23 24 public abstract class JDIVariable extends JDIDebugElement implements IJavaVariable { 25 26 29 private JDIValue fValue; 30 31 38 private int fLastChangeIndex = -1; 39 40 protected final static String jdiStringSignature= "Ljava/lang/String;"; 42 public JDIVariable(JDIDebugTarget target) { 43 super(target); 44 } 45 46 49 public Object getAdapter(Class adapter) { 50 if (adapter == IJavaVariable.class || adapter == IJavaModifiers.class) { 51 return this; 52 } 53 return super.getAdapter(adapter); 54 } 55 56 64 protected final Value getCurrentValue() throws DebugException { 65 try { 66 return retrieveValue(); 67 } catch (RuntimeException e) { 68 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIVariable_exception_retrieving, new String [] {e.toString()}), e); 69 return null; 72 } 73 } 74 75 78 protected abstract Value retrieveValue() throws DebugException; 79 80 87 public IValue getValue() throws DebugException { 88 Value currentValue = getCurrentValue(); 89 if (fValue == null) { 90 fValue = JDIValue.createValue((JDIDebugTarget)getDebugTarget(), currentValue); 91 } else { 92 Value previousValue = fValue.getUnderlyingValue(); 93 if (currentValue == previousValue) { 94 return fValue; 95 } 96 if (previousValue == null || currentValue == null) { 97 fValue = JDIValue.createValue((JDIDebugTarget)getDebugTarget(), currentValue); 98 setChangeCount(getJavaDebugTarget().getSuspendCount()); 99 } else if (!previousValue.equals(currentValue)) { 100 fValue = JDIValue.createValue((JDIDebugTarget)getDebugTarget(), currentValue); 101 setChangeCount(getJavaDebugTarget().getSuspendCount()); 102 } 103 } 104 return fValue; 105 } 106 107 110 public boolean supportsValueModification() { 111 return false; 112 } 113 114 117 public void setValue(String expression) throws DebugException { 118 notSupported(JDIDebugModelMessages.JDIVariable_does_not_support_value_modification); 119 } 120 121 124 public void setValue(IValue value) throws DebugException { 125 notSupported(JDIDebugModelMessages.JDIVariable_does_not_support_value_modification); 126 } 127 128 131 public boolean verifyValue(String expression) throws DebugException { 132 return false; 133 } 134 135 138 public boolean verifyValue(IValue value) { 139 return false; 140 } 141 142 145 public boolean isSynthetic() { 146 return false; 147 } 148 149 152 public boolean isPublic() throws DebugException { 153 return false; 154 } 155 156 159 public boolean isPrivate() throws DebugException { 160 return false; 161 } 162 163 166 public boolean isProtected() throws DebugException { 167 return false; 168 } 169 170 173 public boolean isPackagePrivate() { 174 return false; 175 } 176 177 180 public boolean isStatic() { 181 return false; 182 } 183 184 187 public boolean isFinal() { 188 return false; 189 } 190 191 194 public boolean isLocal() { 195 return false; 196 } 197 198 201 public IJavaType getJavaType() throws DebugException { 202 return JDIType.createType((JDIDebugTarget)getDebugTarget(), getUnderlyingType()); 203 } 204 205 216 protected abstract Type getUnderlyingType() throws DebugException; 217 218 221 protected Value getLastKnownValue() { 222 if (fValue == null) { 223 return null; 224 } 225 return fValue.getUnderlyingValue(); 226 } 227 228 233 protected void setChangeCount(int count) { 234 fLastChangeIndex = count; 235 } 236 237 243 protected int getChangeCount() { 244 return fLastChangeIndex; 245 } 246 247 250 public boolean hasValueChanged() { 251 return getChangeCount() == getJavaDebugTarget().getSuspendCount(); 252 } 253 } 254 | Popular Tags |