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 com.sun.jdi.ClassNotLoadedException; 19 import com.sun.jdi.InvalidTypeException; 20 import com.sun.jdi.LocalVariable; 21 import com.sun.jdi.ReferenceType; 22 import com.sun.jdi.Type; 23 import com.sun.jdi.Value; 24 25 29 30 public class JDILocalVariable extends JDIModificationVariable { 31 34 private LocalVariable fLocal; 35 36 39 private JDIStackFrame fStackFrame; 40 41 45 public JDILocalVariable(JDIStackFrame frame, LocalVariable local) { 46 super((JDIDebugTarget)frame.getDebugTarget()); 47 fStackFrame= frame; 48 fLocal= local; 49 } 50 51 54 protected Value retrieveValue() throws DebugException { 55 synchronized (fStackFrame.getThread()) { 56 if (getStackFrame().isSuspended()) { 57 return getStackFrame().getUnderlyingStackFrame().getValue(fLocal); 58 } 59 } 60 return getLastKnownValue(); 62 } 63 64 67 public String getName() throws DebugException { 68 try { 69 return getLocal().name(); 70 } catch (RuntimeException e) { 71 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDILocalVariable_exception_retrieving_local_variable_name, new String [] {e.toString()}), e); 72 return null; 75 } 76 } 77 78 81 protected void setJDIValue(Value value) throws DebugException { 82 try { 83 synchronized (getStackFrame().getThread()) { 84 getStackFrame().getUnderlyingStackFrame().setValue(getLocal(), value); 85 } 86 fireChangeEvent(DebugEvent.CONTENT); 87 } catch (ClassNotLoadedException e) { 88 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDILocalVariable_exception_modifying_local_variable_value, new String [] {e.toString()}), e); 89 } catch (InvalidTypeException e) { 90 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDILocalVariable_exception_modifying_local_variable_value, new String [] {e.toString()}), e); 91 } catch (RuntimeException e) { 92 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDILocalVariable_exception_modifying_local_variable_value, new String [] {e.toString()}), e); 93 } 94 } 95 96 99 public String getReferenceTypeName() throws DebugException { 100 try { 101 String genericSignature= getLocal().genericSignature(); 102 if (genericSignature != null) { 103 return JDIReferenceType.getTypeName(genericSignature); 104 } 105 try { 106 Type underlyingType= getUnderlyingType(); 107 if (underlyingType instanceof ReferenceType) { 108 return JDIReferenceType.getGenericName((ReferenceType) underlyingType); 109 } 110 } catch (DebugException e) { 111 if (!(e.getStatus().getException() instanceof ClassNotLoadedException)) { 112 throw e; 113 } 114 } 115 return getLocal().typeName(); 116 } catch (RuntimeException e) { 117 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDILocalVariable_exception_retrieving_local_variable_type_name, new String [] {e.toString()}), e); 118 return null; 121 } 122 } 123 124 127 public String getSignature() throws DebugException { 128 try { 129 return getLocal().signature(); 130 } catch (RuntimeException e) { 131 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDILocalVariable_exception_retrieving_local_variable_type_signature, new String [] {e.toString()}), e); 132 return null; 135 } 136 } 137 138 141 public String getGenericSignature() throws DebugException { 142 try { 143 String genericSignature= fLocal.genericSignature(); 144 if (genericSignature != null) { 145 return genericSignature; 146 } 147 return fLocal.signature(); 148 } catch (RuntimeException e) { 149 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDILocalVariable_exception_retrieving_local_variable_type_signature, new String [] {e.toString()}), e); 150 return null; 153 } 154 } 155 156 160 protected void setLocal(LocalVariable local) { 161 fLocal = local; 162 } 163 164 protected LocalVariable getLocal() { 165 return fLocal; 166 } 167 168 protected JDIStackFrame getStackFrame() { 169 return fStackFrame; 170 } 171 172 175 public String toString() { 176 return getLocal().toString(); 177 } 178 179 182 public void setValue(IValue v) throws DebugException { 183 if (verifyValue(v)) { 184 JDIValue value = (JDIValue)v; 185 setJDIValue(value.getUnderlyingValue()); 186 } 187 } 188 189 192 protected Type getUnderlyingType() throws DebugException { 193 try { 194 return getLocal().type(); 195 } catch (ClassNotLoadedException e) { 196 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDILocalVariable_exception_while_retrieving_type_of_local_variable, new String []{e.toString()}), e); 197 } catch (RuntimeException e) { 198 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDILocalVariable_exception_while_retrieving_type_of_local_variable, new String []{e.toString()}), e); 199 } 200 return null; 203 } 204 205 209 public boolean isLocal() { 210 return true; 211 } 212 } 213 | Popular Tags |