~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to lexer/src/org/netbeans/lib/lexer/batch/SkimTokenList.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
package org.netbeans.lib.lexer.batch;
 
43
 
 
44
import java.util.Set;
 
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;
 
52
 
 
53
/**
 
54
 * Filtering token list constructed over character array with an independent
 
55
 * start offset value.
 
56
 * <br>
 
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.
 
60
 * <br>
 
61
 * Other operations are delegated to an original
 
62
 * token list that really holds the tokens.
 
63
 *
 
64
 * @author Miloslav Metelka
 
65
 * @version 1.00
 
66
 */
 
67
 
 
68
public final class SkimTokenList<T extends TokenId> implements TokenList<T> {
 
69
    
 
70
    private CopyTextTokenList<T> tokenList;
 
71
    
 
72
    private int startOffset;
 
73
    
 
74
    private char[] text;
 
75
    
 
76
    
 
77
    public SkimTokenList(CopyTextTokenList<T> tokenList, int startOffset, char[] text) {
 
78
        this.tokenList = tokenList;
 
79
        this.startOffset = startOffset;
 
80
        this.text = text;
 
81
    }
 
82
 
 
83
    public CopyTextTokenList<T> getTokenList() {
 
84
        return tokenList;
 
85
    }
 
86
    
 
87
    public int startOffset() {
 
88
        return tokenList.startOffset();
 
89
    }
 
90
    
 
91
    public int endOffset() {
 
92
        return tokenList.endOffset();
 
93
    }
 
94
    
 
95
    char[] getText() {
 
96
        return text;
 
97
    }
 
98
    
 
99
    void setText(char[] text) {
 
100
        this.text = text;
 
101
    }
 
102
 
 
103
    public int childTokenOffset(int rawOffset) {
 
104
        int offsetShift = (rawOffset >> 16);
 
105
        return startOffset + (rawOffset & 0xFFFF) + offsetShift;
 
106
    }
 
107
 
 
108
    public char childTokenCharAt(int rawOffset, int index) {
 
109
        return text[((rawOffset + index) & 0xFFFF)];
 
110
    }
 
111
 
 
112
    public int modCount() {
 
113
        return 0;
 
114
    }
 
115
 
 
116
    public Object tokenOrEmbeddingContainer(int index) {
 
117
        return tokenList.tokenOrEmbeddingContainer(index);
 
118
    }
 
119
    
 
120
    public AbstractToken<T> replaceFlyToken(
 
121
    int index, AbstractToken<T> flyToken, int offset) {
 
122
        return tokenList.replaceFlyToken(index, flyToken, offset);
 
123
    }
 
124
    
 
125
 
 
126
    public int lookahead(int index) {
 
127
        return tokenList.lookahead(index);
 
128
    }
 
129
 
 
130
    public Object state(int index) {
 
131
        return tokenList.state(index);
 
132
    }
 
133
 
 
134
    public int tokenOffset(int index) {
 
135
        return tokenList.tokenOffset(index);
 
136
    }
 
137
 
 
138
    public int tokenCount() {
 
139
        return tokenList.tokenCount();
 
140
    }
 
141
    
 
142
    public int tokenCountCurrent() {
 
143
        return tokenList.tokenCountCurrent();
 
144
    }
 
145
 
 
146
    public TokenList<?> root() {
 
147
        return tokenList.root();
 
148
    }
 
149
 
 
150
    public TokenHierarchyOperation<?,?> tokenHierarchyOperation() {
 
151
        return tokenList.tokenHierarchyOperation();
 
152
    }
 
153
    
 
154
    public LanguagePath languagePath() {
 
155
        return tokenList.languagePath();
 
156
    }
 
157
 
 
158
    public void wrapToken(int index, EmbeddingContainer embeddingContainer) {
 
159
        tokenList.wrapToken(index, embeddingContainer);
 
160
    }
 
161
 
 
162
    public InputAttributes inputAttributes() {
 
163
        return tokenList.inputAttributes();
 
164
    }
 
165
    
 
166
    public boolean isContinuous() {
 
167
        return tokenList.isContinuous();
 
168
    }
 
169
 
 
170
    public Set<T> skipTokenIds() {
 
171
        return tokenList.skipTokenIds();
 
172
    }
 
173
 
 
174
}