2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.lib.lexer.batch;
45
import org.netbeans.api.lexer.LanguagePath;
46
import org.netbeans.lib.lexer.EmbeddingContainer;
47
import org.netbeans.lib.lexer.TokenList;
48
import org.netbeans.api.lexer.InputAttributes;
49
import org.netbeans.api.lexer.TokenId;
50
import org.netbeans.lib.lexer.TokenHierarchyOperation;
51
import org.netbeans.lib.lexer.token.AbstractToken;
54
* Filtering token list constructed over character array with an independent
57
* It is constructed for batch inputs and it implements
58
* a token list but it only implements translation of raw offsets
59
* into real offsets and retrieving of the characters of token bodies.
61
* Other operations are delegated to an original
62
* token list that really holds the tokens.
64
* @author Miloslav Metelka
68
public final class SkimTokenList<T extends TokenId> implements TokenList<T> {
70
private CopyTextTokenList<T> tokenList;
72
private int startOffset;
77
public SkimTokenList(CopyTextTokenList<T> tokenList, int startOffset, char[] text) {
78
this.tokenList = tokenList;
79
this.startOffset = startOffset;
83
public CopyTextTokenList<T> getTokenList() {
87
public int startOffset() {
88
return tokenList.startOffset();
91
public int endOffset() {
92
return tokenList.endOffset();
99
void setText(char[] text) {
103
public int childTokenOffset(int rawOffset) {
104
int offsetShift = (rawOffset >> 16);
105
return startOffset + (rawOffset & 0xFFFF) + offsetShift;
108
public char childTokenCharAt(int rawOffset, int index) {
109
return text[((rawOffset + index) & 0xFFFF)];
112
public int modCount() {
116
public Object tokenOrEmbeddingContainer(int index) {
117
return tokenList.tokenOrEmbeddingContainer(index);
120
public AbstractToken<T> replaceFlyToken(
121
int index, AbstractToken<T> flyToken, int offset) {
122
return tokenList.replaceFlyToken(index, flyToken, offset);
126
public int lookahead(int index) {
127
return tokenList.lookahead(index);
130
public Object state(int index) {
131
return tokenList.state(index);
134
public int tokenOffset(int index) {
135
return tokenList.tokenOffset(index);
138
public int tokenCount() {
139
return tokenList.tokenCount();
142
public int tokenCountCurrent() {
143
return tokenList.tokenCountCurrent();
146
public TokenList<?> root() {
147
return tokenList.root();
150
public TokenHierarchyOperation<?,?> tokenHierarchyOperation() {
151
return tokenList.tokenHierarchyOperation();
154
public LanguagePath languagePath() {
155
return tokenList.languagePath();
158
public void wrapToken(int index, EmbeddingContainer embeddingContainer) {
159
tokenList.wrapToken(index, embeddingContainer);
162
public InputAttributes inputAttributes() {
163
return tokenList.inputAttributes();
166
public boolean isContinuous() {
167
return tokenList.isContinuous();
170
public Set<T> skipTokenIds() {
171
return tokenList.skipTokenIds();