1 19 20 package org.netbeans.api.lexer; 21 22 import org.netbeans.lib.lexer.LexerUtilsConstants; 23 import org.netbeans.lib.lexer.TokenList; 24 import org.netbeans.lib.lexer.inc.TokenChangeInfo; 25 26 39 40 public final class TokenChange<T extends TokenId> { 41 42 private final TokenChangeInfo<T> info; 43 44 TokenChange(TokenChangeInfo<T> info) { 45 this.info = info; 46 } 47 48 53 public int embeddedChangeCount() { 54 return info.embeddedChanges().length; 55 } 56 57 63 public TokenChange<? extends TokenId> embeddedChange(int index) { 64 return info.embeddedChanges()[index]; 65 } 66 67 74 public <T extends TokenId> TokenChange<T> embeddedChange(Language<T> language) { 75 TokenChange<? extends TokenId>[] ecs = info.embeddedChanges(); 76 for (int i = ecs.length - 1; i >= 0; i--) { 77 TokenChange<? extends TokenId> c = ecs[i]; 78 if (c.language() == language) { 79 @SuppressWarnings ("unchecked") 80 TokenChange<T> ec = (TokenChange<T>)c; 81 return ec; 82 } 83 } 84 return null; 85 } 86 87 91 public Language<T> language() { 92 return LexerUtilsConstants.mostEmbeddedLanguage(languagePath()); 93 } 94 95 99 public LanguagePath languagePath() { 100 return info.currentTokenList().languagePath(); 101 } 102 103 106 public int index() { 107 return info.index(); 108 } 109 110 116 public int offset() { 117 return info.offset(); 118 } 119 120 123 public int removedTokenCount() { 124 TokenList<? extends TokenId> rtl = info.removedTokenList(); 125 return (rtl != null) ? rtl.tokenCount() : 0; 126 } 127 128 140 public TokenSequence<T> removedTokenSequence() { 141 return new TokenSequence<T>(info.removedTokenList()); 142 } 143 144 147 public int addedTokenCount() { 148 return info.addedTokenCount(); 149 } 150 151 158 public TokenSequence<T> currentTokenSequence() { 159 return new TokenSequence<T>(info.currentTokenList()); 160 } 161 162 165 TokenChangeInfo<T> info() { 166 return info; 167 } 168 169 } | Popular Tags |