1 19 20 package org.netbeans.lib.lexer.inc; 21 22 import java.util.Set ; 23 import org.netbeans.api.lexer.LanguagePath; 24 import org.netbeans.api.lexer.InputAttributes; 25 import org.netbeans.api.lexer.Token; 26 import org.netbeans.api.lexer.TokenId; 27 import org.netbeans.lib.lexer.EmbeddingContainer; 28 import org.netbeans.lib.lexer.LexerUtilsConstants; 29 import org.netbeans.lib.lexer.TokenHierarchyOperation; 30 import org.netbeans.lib.lexer.TokenList; 31 import org.netbeans.lib.lexer.token.AbstractToken; 32 import org.netbeans.lib.lexer.token.TextToken; 33 34 40 41 public final class RemovedTokenList<T extends TokenId> implements TokenList<T> { 42 43 private final LanguagePath languagePath; 44 45 private Object [] tokensOrBranches; 46 47 private int removedTokensStartOffset; 48 49 public RemovedTokenList(LanguagePath languagePath, Object [] tokensOrBranches) { 50 this.languagePath = languagePath; 51 this.tokensOrBranches = tokensOrBranches; 52 } 53 54 public LanguagePath languagePath() { 55 return languagePath; 56 } 57 58 public Object tokenOrEmbeddingContainer(int index) { 59 return (index < tokensOrBranches.length) ? tokensOrBranches[index] : null; 60 } 61 62 public int lookahead(int index) { 63 return -1; 64 } 65 66 public Object state(int index) { 67 return null; 68 } 69 70 public int tokenOffset(int index) { 71 Token<? extends TokenId> token = existingToken(index); 72 if (token.isFlyweight()) { 73 int offset = 0; 74 while (--index >= 0) { 75 token = existingToken(index); 76 offset += token.length(); 77 if (!token.isFlyweight()) { 78 return offset + token.offset(null); 80 } 81 } 82 return removedTokensStartOffset + offset; 84 85 } else { return token.offset(null); 87 } 88 } 89 90 private Token<T> existingToken(int index) { 91 return LexerUtilsConstants.token(tokensOrBranches[index]); 92 } 93 94 public synchronized AbstractToken<T> replaceFlyToken( 95 int index, AbstractToken<T> flyToken, int offset) { 96 TextToken<T> nonFlyToken = ((TextToken<T>)flyToken).createCopy(this, offset); 97 tokensOrBranches[index] = nonFlyToken; 98 return nonFlyToken; 99 } 100 101 public int tokenCount() { 102 return tokenCountCurrent(); 103 } 104 105 public int tokenCountCurrent() { 106 return tokensOrBranches.length; 107 } 108 109 public int modCount() { 110 return -1; 111 } 112 113 public int childTokenOffset(int rawOffset) { 114 return rawOffset; 116 } 117 118 public char childTokenCharAt(int rawOffset, int index) { 119 throw new IllegalStateException ("Querying of text for removed tokens not supported"); } 121 122 public void wrapToken(int index, EmbeddingContainer embeddingContainer) { 123 throw new IllegalStateException ("Branching of removed tokens not supported"); } 125 126 public TokenList<? extends TokenId> root() { 127 return this; 128 } 129 130 public TokenHierarchyOperation<?,? extends TokenId> tokenHierarchyOperation() { 131 return null; 132 } 133 134 public InputAttributes inputAttributes() { 135 return null; 136 } 137 138 public boolean isContinuous() { 139 return true; 140 } 141 142 public Set <T> skipTokenIds() { 143 return null; 144 } 145 146 } 147 | Popular Tags |