1 19 20 package org.netbeans.spi.editor.highlighting.support; 21 22 import java.util.Enumeration ; 23 import javax.swing.text.AttributeSet ; 24 import javax.swing.text.DefaultStyledDocument ; 25 import javax.swing.text.Document ; 26 import javax.swing.text.Position ; 27 import javax.swing.text.SimpleAttributeSet ; 28 import junit.framework.AssertionFailedError; 29 import org.netbeans.junit.NbTestCase; 30 import org.netbeans.lib.editor.util.GapList; 31 import org.netbeans.spi.editor.highlighting.*; 32 import org.netbeans.spi.editor.highlighting.performance.SimplePosition; 33 34 38 public class MergingPositionsBagTest extends NbTestCase { 39 40 private static final AttributeSet EMPTY = SimpleAttributeSet.EMPTY; 41 42 private Document doc = new DefaultStyledDocument (); 43 44 45 public MergingPositionsBagTest(String name) { 46 super(name); 47 } 48 49 public void testSimple() { 50 PositionsBag hs = new PositionsBag(doc, true); 51 assertEquals("Sequence should be empty", 0, hs.getMarks().size()); 52 53 hs.addHighlight(pos(10), pos(20), EMPTY); 54 GapList<Position > marks = hs.getMarks(); 55 GapList<AttributeSet > attributes = hs.getAttributes(); 56 assertEquals("Sequence should not be empty", 2, marks.size()); 57 assertEquals("Wrong highlight's start offset", 10, marks.get(0).getOffset()); 58 assertEquals("Wrong highlight's end offset", 20, marks.get(1).getOffset()); 59 assertNull("Wrong highlight's end", attributes.get(1)); 60 61 hs.clear(); 62 assertEquals("Sequence was not cleared", 0, hs.getMarks().size()); 63 } 64 65 public void testAddLeftOverlap() { 66 PositionsBag hs = new PositionsBag(doc, true); 67 SimpleAttributeSet attribsA = new SimpleAttributeSet (); 68 SimpleAttributeSet attribsB = new SimpleAttributeSet (); 69 70 attribsA.addAttribute("set-A", "attribsA"); 71 attribsB.addAttribute("set-B", "attribsB"); 72 73 hs.addHighlight(pos(10), pos(20), attribsA); 74 hs.addHighlight(pos(5), pos(15), attribsB); 75 GapList<Position > marks = hs.getMarks(); 76 GapList<AttributeSet > attributes = hs.getAttributes(); 77 78 assertEquals("Wrong number of highlights", 4, marks.size()); 79 assertEquals("1. highlight - wrong start offset", 5, marks.get(0).getOffset()); 80 assertEquals("1. highlight - wrong end offset", 10, marks.get(1).getOffset()); 81 assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-B"); 82 83 assertEquals("2. highlight - wrong start offset", 10, marks.get(1).getOffset()); 84 assertEquals("2. highlight - wrong end offset", 15, marks.get(2).getOffset()); 85 assertAttribs("2. highlight - wrong attribs", attributes.get(1), "set-A", "set-B"); 86 87 assertEquals("3. highlight - wrong start offset", 15, marks.get(2).getOffset()); 88 assertEquals("3. highlight - wrong end offset", 20, marks.get(3).getOffset()); 89 assertAttribs("3. highlight - wrong attribs", attributes.get(2), "set-A"); 90 assertNull("3. highlight - wrong end", attributes.get(3)); 91 } 92 93 public void testAddRightOverlap() { 94 PositionsBag hs = new PositionsBag(doc, true); 95 SimpleAttributeSet attribsA = new SimpleAttributeSet (); 96 SimpleAttributeSet attribsB = new SimpleAttributeSet (); 97 98 attribsA.addAttribute("set-A", "attribsA"); 99 attribsB.addAttribute("set-B", "attribsB"); 100 101 hs.addHighlight(pos(10), pos(20), attribsA); 102 hs.addHighlight(pos(15), pos(25), attribsB); 103 GapList<Position > marks = hs.getMarks(); 104 GapList<AttributeSet > attributes = hs.getAttributes(); 105 106 assertEquals("Wrong number of highlights", 4, marks.size()); 107 assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset()); 108 assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset()); 109 assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A"); 110 111 assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset()); 112 assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset()); 113 assertAttribs("2. highlight - wrong attribs", attributes.get(1), "set-A", "set-B"); 114 115 assertEquals("3. highlight - wrong start offset", 20, marks.get(2).getOffset()); 116 assertEquals("3. highlight - wrong end offset", 25, marks.get(3).getOffset()); 117 assertAttribs("3. highlight - wrong attribs", attributes.get(2), "set-B"); 118 assertNull("3. highlight - wrong end", attributes.get(3)); 119 } 120 121 public void testAddLeftMatchBiggerOverlap() { 122 PositionsBag hs = new PositionsBag(doc, true); 123 SimpleAttributeSet attribsA = new SimpleAttributeSet (); 124 SimpleAttributeSet attribsB = new SimpleAttributeSet (); 125 126 attribsA.addAttribute("set-A", "attribsA"); 127 attribsB.addAttribute("set-B", "attribsB"); 128 129 hs.addHighlight(pos(10), pos(20), attribsA); 130 hs.addHighlight(pos(10), pos(15), attribsB); 131 GapList<Position > marks = hs.getMarks(); 132 GapList<AttributeSet > attributes = hs.getAttributes(); 133 134 assertEquals("Wrong number of highlights", 3, marks.size()); 135 assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset()); 136 assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset()); 137 assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A", "set-B"); 138 139 assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset()); 140 assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset()); 141 assertAttribs("2. highlight - wrong attribs", attributes.get(1), "set-A"); 142 assertNull("2. highlight - wrong end", attributes.get(2)); 143 } 144 145 public void testAddRightMatchBiggerOverlap() { 146 PositionsBag hs = new PositionsBag(doc, true); 147 SimpleAttributeSet attribsA = new SimpleAttributeSet (); 148 SimpleAttributeSet attribsB = new SimpleAttributeSet (); 149 150 attribsA.addAttribute("set-A", "attribsA"); 151 attribsB.addAttribute("set-B", "attribsB"); 152 153 hs.addHighlight(pos(10), pos(20), attribsA); 154 hs.addHighlight(pos(15), pos(20), attribsB); 155 GapList<Position > marks = hs.getMarks(); 156 GapList<AttributeSet > attributes = hs.getAttributes(); 157 158 assertEquals("Wrong number of highlights", 3, marks.size()); 159 assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset()); 160 assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset()); 161 assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A"); 162 163 assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset()); 164 assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset()); 165 assertAttribs("2. highlight - wrong attribs", attributes.get(1), "set-A", "set-B"); 166 assertNull("2. highlight - wrong end", attributes.get(2)); 167 } 168 169 public void testAddCompleteMatchOverlap() { 170 PositionsBag hs = new PositionsBag(doc, true); 171 SimpleAttributeSet attribsA = new SimpleAttributeSet (); 172 SimpleAttributeSet attribsB = new SimpleAttributeSet (); 173 174 attribsA.addAttribute("set-A", "attribsA"); 175 attribsB.addAttribute("set-B", "attribsB"); 176 177 hs.addHighlight(pos(10), pos(20), attribsA); 178 hs.addHighlight(pos(10), pos(20), attribsB); 179 GapList<Position > marks = hs.getMarks(); 180 GapList<AttributeSet > attributes = hs.getAttributes(); 181 182 assertEquals("Wrong number of highlights", 2, marks.size()); 183 assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset()); 184 assertEquals("1. highlight - wrong end offset", 20, marks.get(1).getOffset()); 185 assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A", "set-B"); 186 assertNull("1. highlight - wrong end", attributes.get(1)); 187 } 188 189 public void testAddBiggerOverlap() { 190 PositionsBag hs = new PositionsBag(doc, true); 191 SimpleAttributeSet attribsA = new SimpleAttributeSet (); 192 SimpleAttributeSet attribsB = new SimpleAttributeSet (); 193 194 attribsA.addAttribute("set-A", "attribsA"); 195 attribsB.addAttribute("set-B", "attribsB"); 196 197 hs.addHighlight(pos(10), pos(20), attribsA); 198 hs.addHighlight(pos(5), pos(25), attribsB); 199 GapList<Position > marks = hs.getMarks(); 200 GapList<AttributeSet > attributes = hs.getAttributes(); 201 202 assertEquals("Wrong number of highlights", 4, marks.size()); 203 assertEquals("1. highlight - wrong start offset", 5, marks.get(0).getOffset()); 204 assertEquals("1. highlight - wrong end offset", 10, marks.get(1).getOffset()); 205 assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-B"); 206 207 assertEquals("2. highlight - wrong start offset", 10, marks.get(1).getOffset()); 208 assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset()); 209 assertAttribs("2. highlight - wrong attribs", attributes.get(1), "set-A", "set-B"); 210 211 assertEquals("3. highlight - wrong start offset", 20, marks.get(2).getOffset()); 212 assertEquals("3. highlight - wrong end offset", 25, marks.get(3).getOffset()); 213 assertAttribs("3. highlight - wrong attribs", attributes.get(2), "set-B"); 214 assertNull("3. highlight - wrong end", attributes.get(3)); 215 } 216 217 public void testAddLeftMatchSmallerOverlap() { 218 PositionsBag hs = new PositionsBag(doc, true); 219 SimpleAttributeSet attribsA = new SimpleAttributeSet (); 220 SimpleAttributeSet attribsB = new SimpleAttributeSet (); 221 222 attribsA.addAttribute("set-A", "attribsA"); 223 attribsB.addAttribute("set-B", "attribsB"); 224 225 hs.addHighlight(pos(10), pos(20), attribsA); 226 hs.addHighlight(pos(10), pos(15), attribsB); 227 GapList<Position > marks = hs.getMarks(); 228 GapList<AttributeSet > attributes = hs.getAttributes(); 229 230 assertEquals("Wrong number of highlights", 3, marks.size()); 231 assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset()); 232 assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset()); 233 assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A", "set-B"); 234 235 assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset()); 236 assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset()); 237 assertAttribs("2. highlight - wrong attribs", attributes.get(1), "set-A"); 238 assertNull("2. highlight - wrong end", attributes.get(2)); 239 } 240 241 public void testAddRightMatchSmallerOverlap() { 242 PositionsBag hs = new PositionsBag(doc, true); 243 SimpleAttributeSet attribsA = new SimpleAttributeSet (); 244 SimpleAttributeSet attribsB = new SimpleAttributeSet (); 245 246 attribsA.addAttribute("set-A", "attribsA"); 247 attribsB.addAttribute("set-B", "attribsB"); 248 249 hs.addHighlight(pos(10), pos(20), attribsA); 250 hs.addHighlight(pos(15), pos(20), attribsB); 251 GapList<Position > marks = hs.getMarks(); 252 GapList<AttributeSet > attributes = hs.getAttributes(); 253 254 assertEquals("Wrong number of highlights", 3, marks.size()); 255 assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset()); 256 assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset()); 257 assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A"); 258 259 assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset()); 260 assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset()); 261 assertAttribs("2. highlight - wrong attribs", attributes.get(1), "set-A", "set-B"); 262 assertNull("2. highlight - wrong end", attributes.get(2)); 263 } 264 265 public void testAddSmallerOverlap() { 266 PositionsBag hs = new PositionsBag(doc, true); 267 SimpleAttributeSet attribsA = new SimpleAttributeSet (); 268 SimpleAttributeSet attribsB = new SimpleAttributeSet (); 269 270 attribsA.addAttribute("set-A", "attribsA"); 271 attribsB.addAttribute("set-B", "attribsB"); 272 273 hs.addHighlight(pos(5), pos(25), attribsA); 274 hs.addHighlight(pos(10), pos(20), attribsB); 275 GapList<Position > marks = hs.getMarks(); 276 GapList<AttributeSet > attributes = hs.getAttributes(); 277 278 assertEquals("Wrong number of highlights", 4, marks.size()); 279 assertEquals("1. highlight - wrong start offset", 5, marks.get(0).getOffset()); 280 assertEquals("1. highlight - wrong end offset", 10, marks.get(1).getOffset()); 281 assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A"); 282 283 assertEquals("2. highlight - wrong start offset", 10, marks.get(1).getOffset()); 284 assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset()); 285 assertAttribs("2. highlight - wrong attribs", attributes.get(1), "set-A", "set-B"); 286 287 assertEquals("3. highlight - wrong start offset", 20, marks.get(2).getOffset()); 288 assertEquals("3. highlight - wrong end offset", 25, marks.get(3).getOffset()); 289 assertAttribs("3. highlight - wrong attribs", attributes.get(0), "set-A"); 290 assertNull("3. highlight - wrong end", attributes.get(3)); 291 } 292 293 public void testOrdering() { 294 PositionsBag hs = new PositionsBag(doc, true); 295 SimpleAttributeSet attribsA = new SimpleAttributeSet (); 296 SimpleAttributeSet attribsB = new SimpleAttributeSet (); 297 298 attribsA.addAttribute("attribute", "value-A"); 299 attribsB.addAttribute("attribute", "value-B"); 300 301 hs.addHighlight(pos(5), pos(15), attribsA); 302 hs.addHighlight(pos(10), pos(20), attribsB); 303 GapList<Position > marks = hs.getMarks(); 304 GapList<AttributeSet > attributes = hs.getAttributes(); 305 306 assertEquals("Wrong number of highlights", 4, marks.size()); 307 assertEquals("1. highlight - wrong attribs", "value-A", attributes.get(0).getAttribute("attribute")); 308 assertEquals("2. highlight - wrong attribs", "value-B", attributes.get(1).getAttribute("attribute")); 309 assertEquals("3. highlight - wrong attribs", "value-B", attributes.get(2).getAttribute("attribute")); 310 assertNull("3. highlight - wrong end", attributes.get(3)); 311 } 312 313 public void testAddMultipleOverlaps() { 314 Object [] src = new Object [] { 315 5, 10, new String [] { "set-A" }, 316 15, 20, new String [] { "set-B" }, 317 25, 30, new String [] { "set-C" }, 318 0, 40, new String [] { "set-D" }, 319 }; 320 Object [] trg = new Object [] { 321 0, 5, new String [] { "set-D" }, 322 5, 10, new String [] { "set-A", "set-D" }, 323 10, 15, new String [] { "set-D" }, 324 15, 20, new String [] { "set-B", "set-D" }, 325 20, 25, new String [] { "set-D" }, 326 25, 30, new String [] { "set-C", "set-D" }, 327 30, 40, new String [] { "set-D" }, 328 }; 329 330 checkMerging(src, trg, true); 331 } 332 333 public void testAddMultipleOverlaps2() { 334 Object [] src = new Object [] { 335 2, 47, new String [] { "set-A" }, 336 49, 74, new String [] { "set-B" }, 337 74, 100, new String [] { "set-C" }, 338 9, 48, new String [] { "set-D" }, 339 49, 98, new String [] { "set-E" }, 340 0, 44, new String [] { "set-F" }, 341 46, 74, new String [] { "set-G" }, 342 74, 100, new String [] { "set-H" }, 343 }; 344 Object [] trg = new Object [] { 345 0, 2, new String [] { "set-F" }, 346 2, 9, new String [] { "set-A", "set-F" }, 347 9, 44, new String [] { "set-A", "set-D", "set-F" }, 348 44, 46, new String [] { "set-A", "set-D" }, 349 46, 47, new String [] { "set-A", "set-D", "set-G" }, 350 47, 48, new String [] { "set-D", "set-G" }, 351 48, 49, new String [] { "set-G" }, 352 49, 74, new String [] { "set-B", "set-E", "set-G" }, 353 74, 98, new String [] { "set-C", "set-E", "set-H" }, 354 98, 100, new String [] { "set-C", "set-H" }, 355 }; 356 357 checkMerging(src, trg, true); 358 } 359 360 public void testAddMultipleOverlaps3() { 361 Object [] src = new Object [] { 362 5, 13, new String [] { "set-A" }, 363 20, 49, new String [] { "set-B" }, 364 50, 53, new String [] { "set-C" }, 365 62, 100, new String [] { "set-D" }, 366 9, 54, new String [] { "set-E" }, 367 57, 100, new String [] { "set-F" }, 368 1, 41, new String [] { "set-G" }, 369 41, 46, new String [] { "set-H" }, 370 54, 83, new String [] { "set-I" }, 371 88, 100, new String [] { "set-J" }, 372 }; 373 Object [] trg = new Object [] { 374 1, 5, new String [] { "set-G" }, 375 5, 9, new String [] { "set-A", "set-G" }, 376 9, 13, new String [] { "set-A", "set-E", "set-G" }, 377 13, 20, new String [] { "set-E", "set-G" }, 378 20, 41, new String [] { "set-B", "set-G", "set-E" }, 379 41, 46, new String [] { "set-B", "set-E", "set-H" }, 380 46, 49, new String [] { "set-B", "set-E" }, 381 49, 50, new String [] { "set-E" }, 382 50, 53, new String [] { "set-C", "set-E" }, 383 53, 54, new String [] { "set-E" }, 384 54, 57, new String [] { "set-I" }, 385 57, 62, new String [] { "set-F", "set-I" }, 386 62, 83, new String [] { "set-D", "set-F", "set-I" }, 387 83, 88, new String [] { "set-D", "set-F" }, 388 88, 100, new String [] { "set-D", "set-F", "set-J" }, 389 }; 390 391 checkMerging(src, trg, true); 392 } 393 394 public void testAddMultipleOverlaps4() { 395 Object [] src = new Object [] { 396 4, 51, new String [] { "set-A-0" }, 397 51, 63, new String [] { "set-A-1" }, 398 69, 75, new String [] { "set-A-2" }, 399 83, 85, new String [] { "set-A-3" }, 400 92, 100, new String [] { "set-A-4" }, 401 5, 17, new String [] { "set-B-0" }, 402 23, 37, new String [] { "set-B-1" }, 403 39, 63, new String [] { "set-B-2" }, 404 69, 100, new String [] { "set-B-3" }, 405 2, 28, new String [] { "set-C-0" }, 406 31, 64, new String [] { "set-C-1" }, 407 66, 93, new String [] { "set-C-2" }, 408 95, 100, new String [] { "set-C-3" }, 409 }; 410 Object [] trg = new Object [] { 411 2, 28, new String [] { "set-C-0" }, 412 28, 31, new String [] { "set-B-1" }, 413 31, 64, new String [] { "set-C-1" }, 414 66, 93, new String [] { "set-C-2" }, 415 93, 95, new String [] { "set-B-3" }, 416 95, 100, new String [] { "set-C-3" }, 417 }; 418 419 checkMerging(src, trg, false); 420 } 421 422 public void checkMerging(Object [] src, Object [] trg, boolean merge) { 423 PositionsBag hs = new PositionsBag(doc, merge); 424 425 for (int i = 0; i < src.length / 3; i++) { 426 SimpleAttributeSet as = new SimpleAttributeSet (); 427 String [] keys = (String []) src[3 * i + 2]; 428 429 for (int j = 0; j < keys.length; j++) { 430 as.addAttribute(keys[j], Boolean.TRUE); 431 } 432 433 hs.addHighlight( 434 pos(((Integer ) src[3 * i + 0]).intValue()), 435 pos(((Integer ) src[3 * i + 1]).intValue()), 436 as 437 ); 438 } 439 440 int lastOffset = Integer.MIN_VALUE; 441 int differentOffsets = 0; 442 443 for (int i = 0; i < trg.length / 3; i++) { 444 if (lastOffset != ((Integer ) trg[3 * i + 0]).intValue()) { 445 differentOffsets++; 446 lastOffset = ((Integer ) trg[3 * i + 0]).intValue(); 447 } 448 if (lastOffset != ((Integer ) trg[3 * i + 1]).intValue()) { 449 differentOffsets++; 450 lastOffset = ((Integer ) trg[3 * i + 1]).intValue(); 451 } 452 } 453 454 GapList<Position > marks = hs.getMarks(); 455 GapList<AttributeSet > attributes = hs.getAttributes(); 456 457 try { 458 assertEquals("Wrong number of highlights", differentOffsets, marks.size()); 459 460 int trgIdx = 0; 461 for (int idx = 0; idx < marks.size(); idx++) { 462 if (attributes.get(idx) == null) { 463 assertTrue("Mark at index 0 must have attributes", idx > 0); 464 continue; 465 } 466 467 assertTrue("Too few marks", idx + 1 < marks.size()); 468 assertTrue("Too many marks", trgIdx < trg.length); 469 470 assertEquals(trgIdx + ". highlight - wrong start offset", 472 ((Integer ) trg[3 * trgIdx + 0]).intValue(), marks.get(idx).getOffset()); 473 assertEquals(trgIdx + ". highlight - wrong end offset", 474 ((Integer ) trg[3 * trgIdx + 1]).intValue(), marks.get(idx + 1).getOffset()); 475 assertAttribs(trgIdx + ". highlight - wrong attribs", 476 attributes.get(idx), (String []) trg[3 * trgIdx + 2]); 477 478 trgIdx++; 479 } 480 481 assertTrue("Wrong number of marks: marks.size() = " + marks.size() + 482 ", trg.length = " + trg.length, 3 * trgIdx == trg.length); 483 484 } catch (AssertionFailedError afe) { 485 dumpMarks(marks, attributes); 486 487 System.out.println("Dump through getHighlights {"); 488 HighlightsSequence sequence = hs.getHighlights(Integer.MIN_VALUE, Integer.MAX_VALUE); 489 for ( ; sequence.moveNext(); ) { 490 System.out.println(" <" + sequence.getStartOffset() + ", " + sequence.getEndOffset() + ">"); 491 } 492 System.out.println("} ---- End of Dump through getHighlights ------------------"); 493 494 throw afe; 495 } 496 } 497 498 private void assertAttribs(String msg, AttributeSet as, String ... keys) { 499 assertEquals(msg, keys.length, as.getAttributeCount()); 500 for (String key : keys) { 501 if (null == as.getAttribute(key)) { 502 fail(msg + " attribute key: " + key); 503 } 504 } 505 } 506 507 private String dumpHighlight(Position start, Position end, AttributeSet attribs) { 508 StringBuilder sb = new StringBuilder (); 509 510 sb.append("<"); 511 sb.append(start == null ? " " : start.getOffset()); 512 sb.append(","); 513 sb.append(end == null ? " " : end.getOffset()); 514 sb.append(","); 515 dumpAttributes(sb, attribs); 516 sb.append(">"); 517 518 return sb.toString(); 519 } 520 521 private String dumpAttributes(StringBuilder sb, AttributeSet attribs) { 522 if (sb == null) { 523 sb = new StringBuilder (); 524 } 525 526 if (attribs == null) { 527 sb.append(" "); 528 } else { 529 Enumeration en = attribs.getAttributeNames(); 530 while (en.hasMoreElements()) { 531 Object attrName = en.nextElement(); 532 Object attrValue = attribs.getAttribute(attrName); 533 534 sb.append("'"); 535 sb.append(attrName.toString()); 536 sb.append("' = '"); 537 sb.append(attrValue == null ? "null" : attrValue.toString()); 538 sb.append("'"); 539 if (en.hasMoreElements()) { 540 sb.append(", "); 541 } 542 } 543 } 544 545 return sb.toString(); 546 } 547 548 private void dumpMarks(GapList<Position > marks, GapList<AttributeSet > attributes) { 549 String signature = marks.getClass() + "@" + Integer.toHexString(System.identityHashCode(marks)); 550 System.out.println("Dumping marks from " + signature + " {"); 551 for(int i = 0; i < marks.size(); i++) { 552 System.out.println("<" + marks.get(i).getOffset() + ", [" + dumpAttributes(null, attributes.get(i)) + "]>"); 553 } 554 System.out.println("} ---- End of Dumping marks from " + signature + " --------"); 555 } 556 557 private Position pos(int offset) { 558 return new SimplePosition(offset); 559 } 560 } 561 | Popular Tags |