KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > inc > TokenListChange


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.lexer.inc;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.api.lexer.LanguagePath;
25 import org.netbeans.api.lexer.TokenId;
26 import org.netbeans.lib.lexer.LAState;
27 import org.netbeans.lib.lexer.TokenList;
28 import org.netbeans.lib.lexer.token.AbstractToken;
29
30 /**
31  * Description of the change in a token list.
32  * <br/>
33  * The change is expressed as a list of removed tokens
34  * plus the current list and index and number of the tokens
35  * added to the current list.
36  *
37  * @author Miloslav Metelka
38  * @version 1.00
39  */

40
41 public final class TokenListChange<T extends TokenId> {
42     
43     private final TokenChangeInfo<T> tokenChangeInfo;
44     
45     private List JavaDoc<AbstractToken<T>> addedTokens;
46
47     private LAState laState;
48
49     private int offsetGapIndex;
50     
51     private int removedEndOffset;
52     
53     private int addedEndOffset;
54     
55     public TokenListChange(TokenList<T> tokenList) {
56         tokenChangeInfo = new TokenChangeInfo<T>(tokenList);
57     }
58     
59     public TokenChangeInfo<T> tokenChangeInfo() {
60         return tokenChangeInfo;
61     }
62     
63     public LanguagePath languagePath() {
64         return tokenChangeInfo.currentTokenList().languagePath();
65     }
66
67     public int index() {
68         return tokenChangeInfo.index();
69     }
70
71     public void setIndex(int tokenIndex) {
72         tokenChangeInfo.setIndex(tokenIndex);
73     }
74     
75     public int offset() {
76         return tokenChangeInfo.offset();
77     }
78
79     public void setOffset(int offset) {
80         tokenChangeInfo.setOffset(offset);
81     }
82     
83     public int offsetGapIndex() {
84         return offsetGapIndex;
85     }
86
87     public void setOffsetGapIndex(int offsetGapIndex) {
88         this.offsetGapIndex = offsetGapIndex;
89     }
90
91     public void addToken(AbstractToken<T> token, int lookahead, Object JavaDoc state) {
92         if (addedTokens == null) {
93             addedTokens = new ArrayList JavaDoc<AbstractToken<T>>(2);
94             laState = LAState.empty();
95         }
96         addedTokens.add(token);
97         laState = laState.add(lookahead, state);
98     }
99     
100     public List JavaDoc<AbstractToken<T>> addedTokens() {
101         return addedTokens;
102     }
103     
104     public void syncAddedTokenCount() {
105         tokenChangeInfo.setAddedTokenCount(addedTokens.size());
106     }
107
108     public void setRemovedTokens(Object JavaDoc[] removedTokensOrBranches) {
109         tokenChangeInfo.setRemovedTokenList(new RemovedTokenList<T>(
110                 languagePath(), removedTokensOrBranches));
111     }
112     
113     public int removedEndOffset() {
114         return removedEndOffset;
115     }
116     
117     public void setRemovedEndOffset(int removedEndOffset) {
118         this.removedEndOffset = removedEndOffset;
119     }
120     
121     public int addedEndOffset() {
122         return addedEndOffset;
123     }
124     
125     public void setAddedEndOffset(int addedEndOffset) {
126         this.addedEndOffset = addedEndOffset;
127     }
128     
129     public LAState laState() {
130         return laState;
131     }
132
133 }
Popular Tags