1 11 package org.eclipse.jdt.internal.debug.core.model; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.debug.core.DebugException; 16 import org.eclipse.debug.core.model.IValue; 17 import org.eclipse.jdt.debug.core.IJavaValue; 18 19 import com.sun.jdi.Value; 20 import com.sun.jdi.VirtualMachine; 21 22 25 public abstract class JDIModificationVariable extends JDIVariable { 26 27 private final static ArrayList fgValidSignatures = new ArrayList (9); 28 static { 29 fgValidSignatures.add("B"); fgValidSignatures.add("C"); fgValidSignatures.add("D"); fgValidSignatures.add("F"); fgValidSignatures.add("I"); fgValidSignatures.add("J"); fgValidSignatures.add("S"); fgValidSignatures.add("Z"); fgValidSignatures.add(jdiStringSignature); } 39 40 public JDIModificationVariable(JDIDebugTarget target) { 41 super(target); 42 } 43 44 47 public boolean supportsValueModification() { 48 return true; 49 } 50 51 protected Value generateVMValue(String expression) throws DebugException { 52 53 String signature= null; 54 Value cValue= getCurrentValue(); 55 VirtualMachine vm= getVM(); 56 if (vm == null) { 57 requestFailed(JDIDebugModelMessages.JDIModificationVariable_Unable_to_generate_value___VM_disconnected__1, null); 58 } 59 if (cValue == null) { 60 signature = jdiStringSignature; 62 } else { 63 signature= cValue.type().signature(); 64 } 65 if (signature.length() > 1 && !signature.equals(jdiStringSignature)) { 66 return null; 67 } 68 Value vmValue= null; 69 try { 70 switch (signature.charAt(0)) { 71 case 'Z' : 72 String flse= Boolean.FALSE.toString(); 73 String tre= Boolean.TRUE.toString(); 74 if (expression.equals(tre) || expression.equals(flse)) { 75 boolean booleanValue= Boolean.valueOf(expression).booleanValue(); 76 vmValue= vm.mirrorOf(booleanValue); 77 } 78 break; 79 case 'B' : 80 byte byteValue= Byte.valueOf(expression).byteValue(); 81 vmValue= vm.mirrorOf(byteValue); 82 break; 83 case 'C' : 84 if (expression.length() == 1) { 85 char charValue= expression.charAt(0); 86 vmValue= vm.mirrorOf(charValue); 87 } else if (expression.length() == 2) { 88 char charValue; 89 if (!(expression.charAt(0) == '\\')) { 90 return null; 91 } 92 switch (expression.charAt(1)) { 93 case 'b': 94 charValue= '\b'; 95 break; 96 case 'f': 97 charValue= '\f'; 98 break; 99 case 'n': 100 charValue= '\n'; 101 break; 102 case 'r': 103 charValue= '\r'; 104 break; 105 case 't': 106 charValue= '\t'; 107 break; 108 case '\'': 109 charValue= '\''; 110 break; 111 case '\"': 112 charValue= '\"'; 113 break; 114 case '\\': 115 charValue= '\\'; 116 break; 117 default : 118 return null; 119 } 120 vmValue= vm.mirrorOf(charValue); 121 } 122 break; 123 case 'S' : 124 short shortValue= Short.valueOf(expression).shortValue(); 125 vmValue= vm.mirrorOf(shortValue); 126 break; 127 case 'I' : 128 int intValue= Integer.valueOf(expression).intValue(); 129 vmValue= vm.mirrorOf(intValue); 130 break; 131 case 'J' : 132 long longValue= Long.valueOf(expression).longValue(); 133 vmValue= vm.mirrorOf(longValue); 134 break; 135 case 'F' : 136 float floatValue= Float.valueOf(expression).floatValue(); 137 vmValue= vm.mirrorOf(floatValue); 138 break; 139 case 'D' : 140 double doubleValue= Double.valueOf(expression).doubleValue(); 141 vmValue= vm.mirrorOf(doubleValue); 142 break; 143 case 'L' : 144 if (expression.equals("null")) { vmValue = null; 146 } else if (expression.equals("\"null\"")) { vmValue = vm.mirrorOf("null"); } else { 149 vmValue= vm.mirrorOf(expression); 150 } 151 break; 152 153 } 154 } catch (NumberFormatException nfe) { 155 return null; 156 } 157 return vmValue; 158 } 159 160 163 public boolean verifyValue(String expression) throws DebugException { 164 IValue value = JDIValue.createValue(getJavaDebugTarget(), generateVMValue(expression)); 165 return verifyValue(value); 166 } 167 168 171 public boolean verifyValue(IValue value) { 172 return value instanceof IJavaValue && 173 value.getDebugTarget().equals(getDebugTarget()); 174 } 175 176 179 public final void setValue(String expression) throws DebugException { 180 Value value= generateVMValue(expression); 181 setJDIValue(value); 182 } 183 184 187 protected abstract void setJDIValue(Value value) throws DebugException; 188 189 } 190 | Popular Tags |