本文整理汇总了Java中org.netbeans.api.lexer.TokenHierarchyEvent.tokenChange方法的典型用法代码示例。如果您正苦于以下问题:Java TokenHierarchyEvent.tokenChange方法的具体用法?Java TokenHierarchyEvent.tokenChange怎么用?Java TokenHierarchyEvent.tokenChange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.lexer.TokenHierarchyEvent
的用法示例。
在下文中一共展示了TokenHierarchyEvent.tokenChange方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tokenHierarchyChanged
import org.netbeans.api.lexer.TokenHierarchyEvent; //导入方法依赖的package包/类
@Override
public void tokenHierarchyChanged(TokenHierarchyEvent evt) {
TokenChange<?> tc = evt.tokenChange();
int affectedArea [] = null;
TokenSequence<? extends TokenId> seq = tc.currentTokenSequence();
if (seq.language().equals(JavadocTokenId.language())) {
// Change inside javadoc
int [] firstSentence = findFirstSentence(seq);
if (firstSentence != null) {
if (tc.offset() <= firstSentence[1]) {
// Change before the end of the first sentence
affectedArea = firstSentence;
}
} else {
// XXX: need the embedding token (i.e. JavaTokenId.JAVADOC_COMMENT*)
// and fire a change in its whole area
affectedArea = new int [] { tc.offset(), evt.affectedEndOffset() };
}
} else {
// The change may or may not involve javadoc, so reset everyting.
// It would be more efficient to traverse the changed area and
// find out whether it really involves javadoc or not.
affectedArea = new int [] { tc.offset(), evt.affectedEndOffset() };
}
if (affectedArea != null) {
synchronized (this) {
version++;
}
fireHighlightsChange(affectedArea[0], affectedArea[1]);
}
}
示例2: testSaveTokensWithinLookahead
import org.netbeans.api.lexer.TokenHierarchyEvent; //导入方法依赖的package包/类
public void testSaveTokensWithinLookahead() throws Exception {
Document doc = new ModificationTextDocument();
String text = "aabc";
doc.insertString(0, text, null);
doc.putProperty(Language.class, TestSaveTokensInLATokenId.language());
TokenHierarchy<?> hi = TokenHierarchy.get(doc);
((AbstractDocument)doc).readLock();
try {
TokenSequence<?> ts = hi.tokenSequence();
ts.moveEnd(); // Force creation of all tokens
LexerTestUtilities.initLastTokenHierarchyEventListening(doc);
} finally {
((AbstractDocument)doc).readUnlock();
}
doc.remove(1, 1);
((AbstractDocument)doc).readLock();
try {
TokenHierarchyEvent evt = LexerTestUtilities.getLastTokenHierarchyEvent(doc);
TokenChange<?> change = evt.tokenChange();
assertEquals(1, change.addedTokenCount());
} finally {
((AbstractDocument)doc).readUnlock();
}
}
示例3: testEmbeddingUpdate
import org.netbeans.api.lexer.TokenHierarchyEvent; //导入方法依赖的package包/类
public void testEmbeddingUpdate() throws Exception {
Document doc = new ModificationTextDocument();
// Assign a language to the document
doc.putProperty(Language.class,TestTokenId.language());
doc.insertString(0, "a/*abc def*/", null);
LexerTestUtilities.initLastTokenHierarchyEventListening(doc);
TokenHierarchy<?> hi = TokenHierarchy.get(doc);
((AbstractDocument)doc).readLock();
try {
TokenSequence<?> ts = hi.tokenSequence();
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "a", 0);
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts,TestTokenId.BLOCK_COMMENT, "/*abc def*/", 1);
TokenSequence<?> ets = ts.embedded();
assertNotNull(ets);
assertTrue(ts.moveNext());
assertTrue(ets.moveNext());
LexerTestUtilities.assertTokenEquals(ets,TestPlainTokenId.WORD, "abc", 3);
assertTrue(ets.moveNext());
LexerTestUtilities.assertTokenEquals(ets,TestPlainTokenId.WHITESPACE, " ", 6);
assertTrue(ets.moveNext());
LexerTestUtilities.assertTokenEquals(ets,TestPlainTokenId.WORD, "def", 7);
assertFalse(ets.moveNext());
} finally {
((AbstractDocument)doc).readUnlock();
}
// Make "axbc" inside the comment
doc.insertString(4, "x", null);
((AbstractDocument)doc).readLock();
try {
TokenHierarchyEvent evt = LexerTestUtilities.getLastTokenHierarchyEvent(doc);
assertNotNull(evt);
TokenChange<?> tc = evt.tokenChange();
assertNotNull(tc);
assertEquals(1, tc.index());
assertEquals(1, tc.offset());
assertEquals(1, tc.addedTokenCount());
assertEquals(1, tc.removedTokenCount());
assertEquals(TestTokenId.language(), tc.language());
assertEquals(1, tc.embeddedChangeCount());
TokenChange<?> etc = tc.embeddedChange(0);
assertEquals(0, etc.index());
assertEquals(3, etc.offset());
assertEquals(1, etc.addedTokenCount()); // 0 to allow for lazy lexing where this would be unknowns
assertEquals(1, etc.removedTokenCount());
assertEquals(TestPlainTokenId.language(), etc.language());
assertEquals(0, etc.embeddedChangeCount());
} finally {
((AbstractDocument)doc).readUnlock();
}
doc.remove(3, 8); // there will be empty /**/ so test empty embedded sequence
doc.insertString(3, "x", null); // there will be empty /**/
}
示例4: testCreateEmbedding
import org.netbeans.api.lexer.TokenHierarchyEvent; //导入方法依赖的package包/类
public void testCreateEmbedding() throws Exception {
Document doc = new ModificationTextDocument();
String text = "abc def ghi";
doc.insertString(0, text, null);
// Assign a language to the document
doc.putProperty(Language.class,TestTokenId.language());
TokenHierarchy<?> hi = TokenHierarchy.get(doc);
LexerTestUtilities.initLastTokenHierarchyEventListening(doc);
((AbstractDocument)doc).readLock();
try {
TokenSequence<?> ts = hi.tokenSequence();
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "abc", 0);
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, " ", 3);
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "def", 4);
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, " ", 7);
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts,TestTokenId.IDENTIFIER, "ghi", 8);
// Extra newline at doc's end is contained in the DocumentUtilities.getText(doc)
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts,TestTokenId.WHITESPACE, "\n", 11);
assertFalse(ts.moveNext());
} finally {
((AbstractDocument)doc).readUnlock();
}
// Do insert
doc.insertString(5, "x", null);
((AbstractDocument)doc).readLock();
try {
// Check the fired event
TokenHierarchyEvent evt = LexerTestUtilities.getLastTokenHierarchyEvent(doc);
assertNotNull(evt);
TokenChange<?> tc = evt.tokenChange();
assertNotNull(tc);
assertEquals(2, tc.index());
assertEquals(4, tc.offset());
assertEquals(1, tc.removedTokenCount());
TokenSequence<?> removedTS = tc.removedTokenSequence();
assertTrue(removedTS.moveNext());
LexerTestUtilities.assertTokenEquals(removedTS, TestTokenId.IDENTIFIER, 3, 4);
assertEquals(1, tc.addedTokenCount());
TokenSequence<?> currentTS = tc.currentTokenSequence();
currentTS.moveIndex(tc.index());
assertTrue(currentTS.moveNext());
LexerTestUtilities.assertTokenEquals(currentTS, TestTokenId.IDENTIFIER, "dxef", 4);
assertEquals(TestTokenId.language(), tc.language());
assertEquals(0, tc.embeddedChangeCount());
} finally {
((AbstractDocument)doc).readUnlock();
}
}