1 19 20 package org.netbeans.api.lexer; 21 22 import java.io.Reader ; 23 import java.util.Set ; 24 import javax.swing.text.Document ; 25 import org.netbeans.lib.lexer.TokenHierarchyOperation; 26 import org.netbeans.lib.lexer.TokenList; 27 import org.netbeans.lib.lexer.inc.DocumentInput; 28 29 49 50 public final class TokenHierarchy<I> { 52 64 public static <D extends Document > TokenHierarchy<D> get(D doc) { 65 DocumentInput<D> di = DocumentInput.get(doc); 66 return di.tokenHierarchyControl().tokenHierarchy(); 67 } 68 69 75 public static TokenHierarchy<Void > create(CharSequence inputText, 76 Language<? extends TokenId> language) { 77 return create(inputText, false, language, null, null); 78 } 79 80 108 public static <T extends TokenId> TokenHierarchy<Void > create( 109 CharSequence inputText, boolean copyInputText, 110 Language<T> language, Set <T> skipTokenIds, InputAttributes inputAttributes) { 111 112 return new TokenHierarchyOperation<Void ,T>(inputText, copyInputText, 113 language, skipTokenIds, inputAttributes).tokenHierarchy(); 114 } 115 116 138 public static <T extends TokenId> TokenHierarchy<Void > create( 139 Reader inputReader, 140 Language<T> language, Set <T> skipTokenIds, InputAttributes inputAttributes) { 141 142 return new TokenHierarchyOperation<Void ,T>(inputReader, 143 language, skipTokenIds, inputAttributes).tokenHierarchy(); 144 } 145 146 147 private TokenHierarchyOperation<I,?> operation; 148 149 TokenHierarchy(TokenHierarchyOperation<I,?> operation) { 150 this.operation = operation; 151 } 152 153 161 public TokenSequence<? extends TokenId> tokenSequence() { 162 @SuppressWarnings ("unchecked") 163 TokenSequence<? extends TokenId> ts = new TokenSequence<TokenId>( 164 (TokenList<TokenId>)operation.checkedTokenList()); 165 return ts; 166 } 167 168 177 public <T extends TokenId> TokenSequence<T> tokenSequence(Language<T> language) { 178 TokenList<? extends TokenId> tokenList = operation.checkedTokenList(); 179 @SuppressWarnings ("unchecked") 180 TokenSequence<T> ts 181 = (tokenList.languagePath().topLanguage() == language) 182 ? new TokenSequence<T>((TokenList<T>)tokenList) 183 : null; 184 return ts; 185 } 186 187 196 public Set <LanguagePath> languagePaths() { 197 return operation.languagePaths(); 198 } 199 200 205 public boolean isMutable() { 206 return operation.isMutable(); 207 } 208 209 223 public I mutableInputSource() { 224 return operation.mutableInputSource(); 225 } 226 227 237 public boolean isActive() { 238 return operation.isActive(); 239 } 240 241 246 public void addTokenHierarchyListener(TokenHierarchyListener listener) { 247 operation.addTokenHierarchyListener(listener); 248 } 249 250 255 public void removeTokenHierarchyListener(TokenHierarchyListener listener) { 256 operation.removeTokenHierarchyListener(listener); 257 } 258 259 316 public TokenHierarchy<I> createSnapshot() { 317 return operation.createSnapshot(); 318 } 319 320 325 public boolean isSnapshot() { 326 return operation.isSnapshot(); 327 } 328 329 335 public void snapshotRelease() { 336 operation.snapshotRelease(); 337 } 338 339 345 public boolean isSnapshotReleased() { 346 return operation.isSnapshotReleased(); 347 } 348 349 355 public TokenHierarchy<I> snapshotOf() { 356 return operation.snapshotOf(); 357 } 358 359 382 public int tokenShiftStartOffset() { 383 return operation.tokenShiftStartOffset(); 384 } 385 386 399 public int tokenShiftEndOffset() { 400 return operation.tokenShiftEndOffset(); 401 } 402 403 407 TokenHierarchyOperation<I,?> operation() { 408 return operation; 409 } 410 411 } 412 | Popular Tags |