1 19 package org.netbeans.lib.lexer.test.inc; 20 21 import java.util.ConcurrentModificationException ; 22 import javax.swing.text.Document ; 23 import org.netbeans.api.lexer.Language; 24 import org.netbeans.api.lexer.Token; 25 import org.netbeans.api.lexer.TokenHierarchy; 26 import org.netbeans.api.lexer.TokenHierarchyEvent; 27 import org.netbeans.api.lexer.TokenSequence; 28 import org.netbeans.api.lexer.TokenUtilities; 29 import org.netbeans.junit.NbTestCase; 30 import org.netbeans.lib.lexer.test.LexerTestUtilities; 31 import org.netbeans.lib.lexer.test.ModificationTextDocument; 32 import org.netbeans.lib.lexer.test.simple.SimpleTokenId; 33 import org.netbeans.spi.lexer.MutableTextInput; 34 35 39 public class TokenHierarchyRebuildTest extends NbTestCase { 40 41 42 public TokenHierarchyRebuildTest(String name) { 43 super(name); 44 } 45 46 public void testRebuild() throws Exception { 47 Document doc = new ModificationTextDocument(); 48 doc.putProperty(Language.class, SimpleTokenId.language()); 49 doc.insertString(0, "abc def", null); 50 TokenHierarchy<?> hi = TokenHierarchy.get(doc); 51 TokenSequence<?> ts = hi.tokenSequence(); 52 assertTrue(ts.moveNext()); 53 Token<?> t = ts.token(); 54 assertNotNull(t); 55 String tText = t.text().toString(); 56 LexerTestUtilities.initLastTokenHierarchyEventListening(doc); 57 58 try { 61 MutableTextInput input = (MutableTextInput)doc.getProperty(MutableTextInput.class); 62 assertNotNull(input); 63 input.tokenHierarchyControl().rebuild(); 64 LexerTestUtilities.initLastDocumentEventListening(doc); 65 } finally { 66 } 68 69 int docLen = doc.getLength(); 71 TokenHierarchyEvent evt = LexerTestUtilities.getLastTokenHierarchyEvent(doc); 72 assertEquals(0, evt.affectedStartOffset()); 73 assertEquals(docLen, evt.affectedEndOffset()); 74 75 try { ts.moveNext(); 77 fail("ConcurrentModificationException not thrown."); 78 } catch (ConcurrentModificationException e) { 79 } 81 82 TokenHierarchy<?> hi2 = TokenHierarchy.get(doc); 83 assertSame(hi, hi2); 84 TokenSequence<?> ts2 = hi2.tokenSequence(); 85 assertTrue(ts2.moveNext()); 86 Token<?> t2 = ts2.token(); 87 88 assertNotSame(t, t2); 89 assertSame(t.id(), t2.id()); 90 assertTrue(TokenUtilities.equals(tText, t2.text())); 91 92 } 93 94 } 95 | Popular Tags |