1 19 20 package org.netbeans.spi.lexer; 21 22 import org.netbeans.api.lexer.Language; 23 import org.netbeans.api.lexer.TokenHierarchy; 24 import org.netbeans.api.lexer.TokenId; 25 import org.netbeans.lib.lexer.TokenHierarchyOperation; 26 27 33 34 public final class TokenHierarchyControl<I> { 35 36 private MutableTextInput<I> input; 37 38 private TokenHierarchyOperation<I,?> operation; 39 40 TokenHierarchyControl(MutableTextInput<I> input) { 41 this.input = input; 42 } 43 44 private <T extends TokenId> void init() { 45 Language<? extends TokenId> language = input.language(); 46 if (language != null) { 47 this.operation = createOperation(language); 48 } 49 } 50 51 private <T extends TokenId> TokenHierarchyOperation<I,T> createOperation(Language<T> language) { 52 return new TokenHierarchyOperation<I,T>(input, language); 53 } 54 55 public synchronized TokenHierarchy<I> tokenHierarchy() { 56 if (operation == null) { 57 init(); 58 } 59 return (operation != null) 60 ? operation.tokenHierarchy() 61 : null; 62 } 63 64 77 public void textModified(int offset, 78 int removedLength, CharSequence removedText, 79 int insertedLength) { 80 if (operation != null) { 81 operation.textModified(offset, removedLength, removedText, insertedLength); 82 } 83 } 84 85 89 public void setActive(boolean active) { 90 if (operation != null) { 91 operation.setActive(active); 92 } 93 } 94 95 public boolean isActive() { 96 return (operation != null) ? operation.isActive() : false; 97 } 98 99 112 public void rebuild() { 113 operation.rebuild(); 114 } 115 116 } 117 | Popular Tags |