View | Details | Raw Unified | Return to bug 286405
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/util/Disassembler.java (-101 / +66 lines)
Lines 158-264 Link Here
158
		});
158
		});
159
	}
159
	}
160
	public static String escapeString(String s) {
160
	public static String escapeString(String s) {
161
		StringBuffer buffer = new StringBuffer();
161
		return decodeStringValue(s);
162
		for (int i = 0, max = s.length(); i < max; i++) {
163
			char c = s.charAt(i);
164
			switch(c) {
165
				case '\b' :
166
					buffer.append("\\b"); //$NON-NLS-1$
167
					break;
168
				case '\t' :
169
					buffer.append("\\t"); //$NON-NLS-1$
170
					break;
171
				case '\n' :
172
					buffer.append("\\n"); //$NON-NLS-1$
173
					break;
174
				case '\f' :
175
					buffer.append("\\f"); //$NON-NLS-1$
176
					break;
177
				case '\r' :
178
					buffer.append("\\r"); //$NON-NLS-1$
179
					break;
180
				case '\0' :
181
					buffer.append("\\0"); //$NON-NLS-1$
182
					break;
183
				case '\1' :
184
					buffer.append("\\1"); //$NON-NLS-1$
185
					break;
186
				case '\2' :
187
					buffer.append("\\2"); //$NON-NLS-1$
188
					break;
189
				case '\3' :
190
					buffer.append("\\3"); //$NON-NLS-1$
191
					break;
192
				case '\4' :
193
					buffer.append("\\4"); //$NON-NLS-1$
194
					break;
195
				case '\5' :
196
					buffer.append("\\5"); //$NON-NLS-1$
197
					break;
198
				case '\6' :
199
					buffer.append("\\6"); //$NON-NLS-1$
200
					break;
201
				case '\7' :
202
					buffer.append("\\7"); //$NON-NLS-1$
203
					break;
204
				default:
205
					buffer.append(c);
206
			}
207
		}
208
		return buffer.toString();
209
	}
162
	}
210
163
211
	static String decodeStringValue(char[] chars) {
164
	static String decodeStringValue(char[] chars) {
212
		StringBuffer buffer = new StringBuffer();
165
		StringBuffer buffer = new StringBuffer();
213
		for (int i = 0, max = chars.length; i < max; i++) {
166
		for (int i = 0, max = chars.length; i < max; i++) {
214
			char c = chars[i];
167
			char c = chars[i];
215
			switch(c) {
168
			escapeChar(buffer, c);
216
				case '\b' :
217
					buffer.append("\\b"); //$NON-NLS-1$
218
					break;
219
				case '\t' :
220
					buffer.append("\\t"); //$NON-NLS-1$
221
					break;
222
				case '\n' :
223
					buffer.append("\\n"); //$NON-NLS-1$
224
					break;
225
				case '\f' :
226
					buffer.append("\\f"); //$NON-NLS-1$
227
					break;
228
				case '\r' :
229
					buffer.append("\\r"); //$NON-NLS-1$
230
					break;
231
				case '\0' :
232
					buffer.append("\\0"); //$NON-NLS-1$
233
					break;
234
				case '\1' :
235
					buffer.append("\\1"); //$NON-NLS-1$
236
					break;
237
				case '\2' :
238
					buffer.append("\\2"); //$NON-NLS-1$
239
					break;
240
				case '\3' :
241
					buffer.append("\\3"); //$NON-NLS-1$
242
					break;
243
				case '\4' :
244
					buffer.append("\\4"); //$NON-NLS-1$
245
					break;
246
				case '\5' :
247
					buffer.append("\\5"); //$NON-NLS-1$
248
					break;
249
				case '\6' :
250
					buffer.append("\\6"); //$NON-NLS-1$
251
					break;
252
				case '\7' :
253
					buffer.append("\\7"); //$NON-NLS-1$
254
					break;
255
				default:
256
					buffer.append(c);
257
			}
258
		}
169
		}
259
		return buffer.toString();
170
		return buffer.toString();
260
	}
171
	}
261
172
173
	private static void escapeChar(StringBuffer buffer, char c) {
174
		switch(c) {
175
			case '\b' :
176
				buffer.append("\\b"); //$NON-NLS-1$
177
				break;
178
			case '\t' :
179
				buffer.append("\\t"); //$NON-NLS-1$
180
				break;
181
			case '\n' :
182
				buffer.append("\\n"); //$NON-NLS-1$
183
				break;
184
			case '\f' :
185
				buffer.append("\\f"); //$NON-NLS-1$
186
				break;
187
			case '\r' :
188
				buffer.append("\\r"); //$NON-NLS-1$
189
				break;
190
			case '\0' :
191
				buffer.append("\\0"); //$NON-NLS-1$
192
				break;
193
			case '\1' :
194
				buffer.append("\\1"); //$NON-NLS-1$
195
				break;
196
			case '\2' :
197
				buffer.append("\\2"); //$NON-NLS-1$
198
				break;
199
			case '\3' :
200
				buffer.append("\\3"); //$NON-NLS-1$
201
				break;
202
			case '\4' :
203
				buffer.append("\\4"); //$NON-NLS-1$
204
				break;
205
			case '\5' :
206
				buffer.append("\\5"); //$NON-NLS-1$
207
				break;
208
			case '\6' :
209
				buffer.append("\\6"); //$NON-NLS-1$
210
				break;
211
			case '\7' :
212
				buffer.append("\\7"); //$NON-NLS-1$
213
				break;
214
			default:
215
				buffer.append(c);
216
		}
217
	}
218
262
	static String decodeStringValue(String s) {
219
	static String decodeStringValue(String s) {
263
		return decodeStringValue(s.toCharArray());
220
		return decodeStringValue(s.toCharArray());
264
	}
221
	}
Lines 337-358 Link Here
337
						value = Double.toString(constantPoolEntry.getDoubleValue());
294
						value = Double.toString(constantPoolEntry.getDoubleValue());
338
						break;
295
						break;
339
					case IConstantPoolConstant.CONSTANT_Integer:
296
					case IConstantPoolConstant.CONSTANT_Integer:
297
						StringBuffer temp = new StringBuffer();
340
						switch(annotationComponentValue.getTag()) {
298
						switch(annotationComponentValue.getTag()) {
341
							case IAnnotationComponentValue.CHAR_TAG :
299
							case IAnnotationComponentValue.CHAR_TAG :
342
								value = "'" + (char) constantPoolEntry.getIntegerValue() + "'"; //$NON-NLS-1$//$NON-NLS-2$
300
								temp.append('\'');
301
								escapeChar(temp, (char) constantPoolEntry.getIntegerValue());
302
								temp.append('\'');
343
								break;
303
								break;
344
							case IAnnotationComponentValue.BOOLEAN_TAG :
304
							case IAnnotationComponentValue.BOOLEAN_TAG :
345
								value = constantPoolEntry.getIntegerValue() == 1 ? "true" : "false";//$NON-NLS-1$//$NON-NLS-2$
305
								temp.append(constantPoolEntry.getIntegerValue() == 1 ? "true" : "false");//$NON-NLS-1$//$NON-NLS-2$
346
								break;
306
								break;
347
							case IAnnotationComponentValue.BYTE_TAG :
307
							case IAnnotationComponentValue.BYTE_TAG :
348
								value = "(byte) " + constantPoolEntry.getIntegerValue(); //$NON-NLS-1$
308
								temp.append("(byte) ").append(constantPoolEntry.getIntegerValue()); //$NON-NLS-1$
349
								break;
309
								break;
350
							case IAnnotationComponentValue.SHORT_TAG :
310
							case IAnnotationComponentValue.SHORT_TAG :
351
								value =  "(short) " + constantPoolEntry.getIntegerValue(); //$NON-NLS-1$
311
								temp.append("(short) ").append(constantPoolEntry.getIntegerValue()); //$NON-NLS-1$
352
								break;
312
								break;
353
							case IAnnotationComponentValue.INTEGER_TAG :
313
							case IAnnotationComponentValue.INTEGER_TAG :
354
								value =  "(int) " + constantPoolEntry.getIntegerValue(); //$NON-NLS-1$
314
								temp.append("(int) ").append(constantPoolEntry.getIntegerValue()); //$NON-NLS-1$
355
						}
315
						}
316
						value = String.valueOf(temp);
356
						break;
317
						break;
357
					case IConstantPoolConstant.CONSTANT_Utf8:
318
					case IConstantPoolConstant.CONSTANT_Utf8:
358
						value = "\"" + decodeStringValue(constantPoolEntry.getUtf8Value()) + "\"";//$NON-NLS-1$//$NON-NLS-2$
319
						value = "\"" + decodeStringValue(constantPoolEntry.getUtf8Value()) + "\"";//$NON-NLS-1$//$NON-NLS-2$
Lines 1836-1857 Link Here
1836
						value = Double.toString(constantPoolEntry.getDoubleValue());
1797
						value = Double.toString(constantPoolEntry.getDoubleValue());
1837
						break;
1798
						break;
1838
					case IConstantPoolConstant.CONSTANT_Integer:
1799
					case IConstantPoolConstant.CONSTANT_Integer:
1800
						StringBuffer temp = new StringBuffer();
1839
						switch(annotationComponentValue.getTag()) {
1801
						switch(annotationComponentValue.getTag()) {
1840
							case IAnnotationComponentValue.CHAR_TAG :
1802
							case IAnnotationComponentValue.CHAR_TAG :
1841
								value = "'" + (char) constantPoolEntry.getIntegerValue() + "'"; //$NON-NLS-1$//$NON-NLS-2$
1803
								temp.append('\'');
1804
								escapeChar(temp, (char) constantPoolEntry.getIntegerValue());
1805
								temp.append('\'');
1842
								break;
1806
								break;
1843
							case IAnnotationComponentValue.BOOLEAN_TAG :
1807
							case IAnnotationComponentValue.BOOLEAN_TAG :
1844
								value = constantPoolEntry.getIntegerValue() == 1 ? "true" : "false";//$NON-NLS-1$//$NON-NLS-2$
1808
								temp.append(constantPoolEntry.getIntegerValue() == 1 ? "true" : "false");//$NON-NLS-1$//$NON-NLS-2$
1845
								break;
1809
								break;
1846
							case IAnnotationComponentValue.BYTE_TAG :
1810
							case IAnnotationComponentValue.BYTE_TAG :
1847
								value = "(byte) " + constantPoolEntry.getIntegerValue(); //$NON-NLS-1$
1811
								temp.append("(byte) ").append(constantPoolEntry.getIntegerValue()); //$NON-NLS-1$
1848
								break;
1812
								break;
1849
							case IAnnotationComponentValue.SHORT_TAG :
1813
							case IAnnotationComponentValue.SHORT_TAG :
1850
								value =  "(short) " + constantPoolEntry.getIntegerValue(); //$NON-NLS-1$
1814
								temp.append("(short) ").append(constantPoolEntry.getIntegerValue()); //$NON-NLS-1$
1851
								break;
1815
								break;
1852
							case IAnnotationComponentValue.INTEGER_TAG :
1816
							case IAnnotationComponentValue.INTEGER_TAG :
1853
								value =  "(int) " + constantPoolEntry.getIntegerValue(); //$NON-NLS-1$
1817
								temp.append("(int) ").append(constantPoolEntry.getIntegerValue()); //$NON-NLS-1$
1854
						}
1818
						}
1819
						value = String.valueOf(temp);
1855
						break;
1820
						break;
1856
					case IConstantPoolConstant.CONSTANT_Utf8:
1821
					case IConstantPoolConstant.CONSTANT_Utf8:
1857
						value = "\"" + decodeStringValue(constantPoolEntry.getUtf8Value()) + "\"";//$NON-NLS-1$//$NON-NLS-2$
1822
						value = "\"" + decodeStringValue(constantPoolEntry.getUtf8Value()) + "\"";//$NON-NLS-1$//$NON-NLS-2$

Return to bug 286405