1 19 20 package org.netbeans.editor; 21 22 import java.awt.event.ActionEvent ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import javax.swing.text.JTextComponent ; 26 import javax.swing.text.BadLocationException ; 27 import javax.swing.text.TextAction ; 28 import javax.swing.text.Segment ; 29 30 36 37 public class EditorDebug { 38 39 private EditorDebug() { 40 } 42 43 public static void dumpPlanes(BaseDocument doc) { 44 62 } 63 64 public static void dumpSyntaxMarks(final BaseDocument doc) { 65 System.out.println("--------------------------- DUMP OF SYNTAX MARKS --------------------------------"); final int docLen = doc.getLength(); 67 136 System.out.println("--------------------------------------------------------------------------------\n"); } 138 139 public static void test(JTextComponent component) { 140 181 } 182 183 public static void checkSettings(Class kitClass) throws Exception { 184 int readBufferSize = SettingsUtil.getInteger(kitClass, SettingsNames.READ_BUFFER_SIZE, 185 SettingsDefaults.defaultReadBufferSize); 186 187 int writeBufferSize = SettingsUtil.getInteger(kitClass, SettingsNames.WRITE_BUFFER_SIZE, 188 SettingsDefaults.defaultWriteBufferSize); 189 190 int readMarkDistance = SettingsUtil.getInteger(kitClass, SettingsNames.READ_MARK_DISTANCE, 191 SettingsDefaults.defaultReadMarkDistance); 192 193 int markDistance = SettingsUtil.getInteger(kitClass, SettingsNames.MARK_DISTANCE, 194 SettingsDefaults.defaultMarkDistance); 195 196 int maxMarkDistance = SettingsUtil.getInteger(kitClass, SettingsNames.MAX_MARK_DISTANCE, 197 SettingsDefaults.defaultMaxMarkDistance); 198 199 int minMarkDistance = SettingsUtil.getInteger(kitClass, SettingsNames.MIN_MARK_DISTANCE, 200 SettingsDefaults.defaultMinMarkDistance); 201 202 int syntaxUpdateBatchSize = SettingsUtil.getInteger(kitClass, SettingsNames.SYNTAX_UPDATE_BATCH_SIZE, 203 SettingsDefaults.defaultSyntaxUpdateBatchSize); 204 205 206 if (maxMarkDistance < markDistance) { 208 throw new Exception ("maxMarkDistance=" + maxMarkDistance + " < markDistance=" + markDistance); } 211 212 if (markDistance < minMarkDistance) { 213 throw new Exception ("markDistance=" + markDistance + " < minMarkDistance=" + minMarkDistance); } 216 217 if (readMarkDistance < minMarkDistance) { 218 throw new Exception ("readMarkDistance=" + readMarkDistance + " < minMarkDistance=" + minMarkDistance); } 221 222 if (syntaxUpdateBatchSize < maxMarkDistance) { 223 throw new Exception ("syntaxUpdateBatchSize=" + syntaxUpdateBatchSize + " < maxMarkDistance=" + maxMarkDistance); } 226 227 } 228 229 230 public static String debugString(String s) { 231 return (s != null) ? debugChars(s.toCharArray(), 0, s.length()) 232 : "NULL STRING"; } 234 235 public static String debugChars(Segment seg) { 236 return debugChars(seg.array, seg.offset, seg.count); 237 } 238 239 public static String debugChars(char chars[]) { 240 return debugChars(chars, 0, chars.length); 241 } 242 243 244 public static String debugChars(char chars[], int offset, int len) { 245 if (len < 0) { 246 return "EditorDebug.debugChars() !ERROR! len=" + len + " < 0"; } 248 if (offset < 0) { 249 return "EditorDebug.debugChars() !ERROR! offset=" + offset + " < 0"; } 251 if (offset + len > chars.length) { 252 return "EditorDebug.debugChars() !ERROR! offset=" + offset + " + len=" + len + " > chars.length=" + chars.length; } 255 StringBuffer sb = new StringBuffer (len); 256 int endOffset = offset + len; 257 for (; offset < endOffset; offset++) { 258 switch (chars[offset]) { 259 case '\n': 260 sb.append("\\n"); break; 262 case '\t': 263 sb.append("\\t"); break; 265 case '\r': 266 sb.append("\\r"); break; 268 default: 269 sb.append(chars[offset]); 270 } 271 } 272 return sb.toString(); 273 } 274 275 public static String debugChar(char ch) { 276 switch (ch) { 277 case '\n': 278 return "\\n"; case '\t': 280 return "\\t"; case '\r': 282 return "\\r"; default: 284 return String.valueOf(ch); 285 } 286 } 287 288 public static String debugPairs(int[] pairs) { 289 String ret; 290 if (pairs == null) { 291 ret = "Null pairs"; } else if (pairs.length == 0) { 293 ret = "No pairs"; } else { 295 StringBuffer sb = new StringBuffer (); 296 for (int i = 0; i < pairs.length; i += 2) { 297 sb.append('['); 298 sb.append(pairs[i]); 299 sb.append(", "); sb.append(pairs[i + 1]); 301 if (i < pairs.length - 1) { 302 sb.append("]\n"); } 304 } 305 ret = sb.toString(); 306 } 307 308 return ret; 309 } 310 311 public static String debugArray(Object [] array) { 312 String ret; 313 if (array == null) { 314 ret = "Null array"; } else if (array.length == 0) { 316 ret = "Empty array"; } else { 318 StringBuffer sb = new StringBuffer (); 319 for (int i = 0; i < array.length; i++) { 320 sb.append('['); 321 sb.append(i); 322 sb.append("]="); sb.append(array[i]); 324 if (i != array.length - 1) { 325 sb.append('\n'); 326 } 327 } 328 ret = sb.toString(); 329 } 330 return ret; 331 } 332 333 public static String debugArray(int[] array) { 334 String ret; 335 if (array == null) { 336 ret = "Null array"; } else if (array.length == 0) { 338 ret = "Empty array"; } else { 340 StringBuffer sb = new StringBuffer (); 341 for (int i = 0; i < array.length; i++) { 342 sb.append('['); 343 sb.append(i); 344 sb.append("]="); sb.append(array[i]); 346 if (i != array.length - 1) { 347 sb.append('\n'); 348 } 349 } 350 ret = sb.toString(); 351 } 352 return ret; 353 } 354 355 public static String debugBlocks(BaseDocument doc, int[] blocks) { 356 String ret; 357 if (blocks == null) { 358 ret = "Null blocks"; } else if (blocks.length == 0) { 360 ret = "Empty blocks"; } else if (blocks.length % 2 != 0) { 362 ret = "Blocks.length=" + blocks.length + " is not even!"; } else { 364 StringBuffer sb = new StringBuffer (); 365 for (int i = 0; i < blocks.length; i += 2) { 366 sb.append('['); 367 sb.append(i); 368 sb.append("]=("); sb.append(blocks[i]); 370 sb.append(", "); sb.append(blocks[i + 1]); 372 sb.append(") or ("); sb.append(Utilities.debugPosition(doc, blocks[i])); 374 sb.append(", "); sb.append(Utilities.debugPosition(doc, blocks[i + 1])); 376 sb.append(')'); 377 378 if (i != blocks.length - 1) { 379 sb.append('\n'); 380 } 381 } 382 ret = sb.toString(); 383 } 384 return ret; 385 } 386 387 public static String debugList(List l) { 388 String ret; 389 if (l == null) { 390 ret = "Null list"; } else if (l.size() == 0) { 392 ret = "Empty list"; } else { 394 int cnt = l.size(); 395 StringBuffer sb = new StringBuffer (); 396 for (int i = 0; i < cnt; i++) { 397 sb.append('['); 398 sb.append(i); 399 sb.append("]="); sb.append(l.get(i)); 401 if (i != cnt - 1) { 402 sb.append('\n'); 403 } 404 } 405 ret = sb.toString(); 406 } 407 return ret; 408 } 409 410 public static String debugIterator(Iterator i) { 411 String ret; 412 if (i == null) { 413 ret = "Null iterator"; } else if (!i.hasNext()) { 415 ret = "Empty iterator"; } else { 417 StringBuffer sb = new StringBuffer (); 418 int ind = 0; 419 while (i.hasNext()) { 420 sb.append('['); 421 sb.append(ind++); 422 sb.append("]="); sb.append(i.next().toString()); 424 if (i.hasNext()) { 425 sb.append('\n'); 426 } 427 } 428 ret = sb.toString(); 429 } 430 return ret; 431 } 432 433 } 434 | Popular Tags |