1 11 package org.eclipse.debug.internal.ui.views.memory.renderings; 12 13 import java.math.BigInteger ; 14 15 import org.eclipse.debug.core.model.MemoryByte; 16 import org.eclipse.debug.internal.ui.DebugUIPlugin; 17 import org.eclipse.debug.ui.IDebugUIConstants; 18 19 23 public class SignedIntegerRendering extends AbstractIntegerRendering { 24 25 private int fColSize; 26 private BigInteger fMax; 27 private BigInteger fMin; 28 29 33 public SignedIntegerRendering(String renderingId) { 34 super(renderingId); 35 } 36 37 private String convertToString(byte[] byteArray, int columnSize, int endianess) 38 { 39 String ret; 40 long result = 0; 41 42 if (columnSize == 1) 43 { 44 result = byteArray[0]; 45 } 46 else if (columnSize == 2) 47 { 48 result = RenderingsUtil.convertByteArrayToShort(byteArray, endianess); 49 } 50 else if (columnSize == 4) 51 { 52 result = RenderingsUtil.convertByteArrayToInt(byteArray, endianess); 53 } 54 else if (columnSize == 8) 55 { 56 result = RenderingsUtil.convertByteArrayToLong(byteArray, endianess); 57 } 58 else if (columnSize == 16) 59 { 60 BigInteger bigRet = RenderingsUtil.convertByteArrayToSignedBigInt(byteArray, endianess); 61 return bigRet.toString(); 62 } 63 else 64 { 65 BigInteger bigRet = RenderingsUtil.convertByteArrayToSignedBigInt(byteArray, endianess, columnSize); 66 return bigRet.toString(); 67 } 68 69 ret = new Long (result).toString(); 70 71 return ret; 72 } 73 74 private byte[] convertToBytes(int colSize, String newValue, int endianess) 75 { 76 try { 77 byte[] bytes; 78 if (colSize == 1) 79 { 80 byte x = Byte.parseByte(newValue); 81 bytes = new byte[1]; 82 bytes[0] = x; 83 } 84 else if (colSize == 2) 85 { 86 short i = Short.parseShort(newValue); 87 bytes = RenderingsUtil.convertShortToByteArray(i, endianess); 88 } 89 else if (colSize == 4) 90 { 91 int i = Integer.parseInt(newValue); 92 bytes = RenderingsUtil.convertIntToByteArray(i, endianess); 93 } 94 else if (colSize == 8) 95 { 96 long i = Long.parseLong(newValue); 97 bytes = RenderingsUtil.convertLongToByteArray(i, endianess); 98 } 99 else if (colSize == 16) 100 { 101 BigInteger i = new BigInteger (newValue); 104 bytes = RenderingsUtil.convertBigIntegerToByteArray(i, endianess); 105 106 return bytes; 107 } 108 else 109 { 110 BigInteger i = new BigInteger (newValue); 111 112 if (fColSize != colSize) 115 { 116 fColSize = colSize; 117 fMax = BigInteger.valueOf(2); 118 fMax = fMax.pow(colSize*8-1); 119 fMin = fMax.multiply(BigInteger.valueOf(-1)); 120 fMax = fMax.subtract(BigInteger.valueOf(1)); 121 } 122 123 if (i.compareTo(fMax) > 0 || i.compareTo(fMin) < 0) 124 throw new NumberFormatException (); 125 126 bytes = RenderingsUtil.convertSignedBigIntToByteArray(i, endianess, colSize); 127 return bytes; 128 } 129 130 return bytes; 131 } catch (NumberFormatException e) { 132 throw e; 133 } 134 } 135 136 139 public String getString(String dataType, BigInteger address, MemoryByte[] data) { 140 141 boolean invalid = false; 142 String paddedStr = DebugUIPlugin.getDefault().getPreferenceStore().getString(IDebugUIConstants.PREF_PADDED_STR); 143 for (int i=0; i<data.length; i++) 144 { 145 if (!data[i].isReadable()) 146 { 147 invalid = true; 148 break; 149 } 150 } 151 152 if (invalid) 153 { 154 StringBuffer strBuf = new StringBuffer (); 155 for (int i=0; i<data.length; i++) 156 { 157 strBuf.append(paddedStr); 158 } 159 return strBuf.toString(); 160 } 161 162 int columnSize = getBytesPerColumn(); 163 164 int endianess = getDisplayEndianess(); 167 if (endianess == RenderingsUtil.ENDIANESS_UNKNOWN) 168 endianess = getBytesEndianess(data); 169 170 byte[] byteArray = new byte[data.length]; 171 for (int i=0; i<byteArray.length;i ++) 172 { 173 byteArray[i] = data[i].getValue(); 174 } 175 176 if (RenderingsUtil.ENDIANESS_UNKNOWN == endianess) 178 { 179 StringBuffer strBuf = new StringBuffer (); 180 for (int i=0; i<byteArray.length; i++) 181 { 182 strBuf.append(paddedStr); 183 } 184 return strBuf.toString(); 185 } 186 return convertToString(byteArray, columnSize, endianess); 187 } 188 189 192 public byte[] getBytes(String dataType, BigInteger address, MemoryByte[] currentValues, String data) { 193 194 int columnSize = getBytesPerColumn(); 195 196 int endianess = getDisplayEndianess(); 199 if (endianess == RenderingsUtil.ENDIANESS_UNKNOWN) 200 endianess = getBytesEndianess(currentValues); 201 202 if (endianess == RenderingsUtil.ENDIANESS_UNKNOWN) 204 { 205 byte[] retBytes = new byte[currentValues.length]; 206 for (int i=0 ;i<currentValues.length; i++) 207 retBytes[i] = currentValues[i].getValue(); 208 return retBytes; 209 } 210 211 return convertToBytes(columnSize, data, endianess); 212 } 213 } 214 | Popular Tags |