KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > definitions > reducedmodel > ReducedToken


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.definitions.reducedmodel;
35
36 /** The representation of document text in the reduced model.
37  * It is the core atomic piece.
38  * @version $Id: ReducedToken.java 3784 2006-04-16 05:17:56Z rcartwright $
39  */

40 public abstract class ReducedToken implements ReducedModelStates {
41   private ReducedModelState _state;
42
43   public ReducedToken(ReducedModelState state) {
44     _state = state;
45   }
46
47   /** Get the size of the token.
48    * @return the number of characters represented by the token
49    */

50   public abstract int getSize();
51
52   /** Get the type of the token.
53    * @return a String representation of the token type
54    */

55   public abstract String JavaDoc getType();
56
57   /** Set the type of the token
58    * @param type a String representation of the new token type
59    */

60   public abstract void setType(String JavaDoc type);
61
62   /** Flip between open and closed. Valid only for braces. */
63   public abstract void flip();
64
65   /** Determine if the given token is a open/close match with this.
66    * @param other another ReducedToken
67    * @return true if there is a match
68    */

69   public abstract boolean isMatch(ReducedToken other);
70
71   /** Get the shadowing state of the token.
72    * @return FREE | INSIDE_SINGLE_QUOTE | INSIDE_DOUBLE_QUOTE | INSIDE_LINE_COMMENT| INSIDE_BLOCK_COMMENT
73    */

74   public ReducedModelState getState() { return _state; }
75
76   /** Returns whether the current char is highlighted. / / beginning a comment
77    * would be highlighted but free, so its not the same as getState
78    */

79   public int getHighlightState() {
80     String JavaDoc type = getType();
81     if (type.equals("//") || (_state == INSIDE_LINE_COMMENT) || type.equals("/*")
82         || type.equals("*/") || (_state == INSIDE_BLOCK_COMMENT)) {
83       return HighlightStatus.COMMENTED;
84     }
85     if ((type.equals("'") && (_state == FREE)) || (_state == INSIDE_SINGLE_QUOTE)) {
86       return HighlightStatus.SINGLE_QUOTED;
87     }
88     if ((type.equals("\"") && (_state == FREE)) || (_state == INSIDE_DOUBLE_QUOTE)) {
89       return HighlightStatus.DOUBLE_QUOTED;
90     }
91     return HighlightStatus.NORMAL;
92   }
93
94   /** Set the shadowing state of the token.
95    * @param state
96    */

97   public void setState(ReducedModelState state) {
98     _state = state;
99   }
100
101   /** Indicates whether this brace is shadowed. Shadowing occurs when a brace has been swallowed by a
102    * comment or an open quote.
103    * @return true if the brace is shadowed.
104    */

105   public boolean isShadowed() { return _state != FREE; }
106
107   /** Indicates whether this brace is inside quotes.
108    * @return true if the brace is inside quotes.
109    */

110   public boolean isQuoted() {
111     return _state == INSIDE_DOUBLE_QUOTE;
112   }
113
114   /** Indicates whether this brace is commented out.
115    * @return true if the brace is hidden by comments.
116    */

117   public boolean isCommented() { return inBlockComment() || inLineComment(); }
118
119   /** Determines whether the current location is inside a block comment.
120    * @return true or false
121    */

122   public boolean inBlockComment() { return _state == INSIDE_BLOCK_COMMENT; }
123
124   /** Determines whether the current location is inside a line comment.
125    * @return true or false
126    */

127   public boolean inLineComment() { return _state == INSIDE_LINE_COMMENT; }
128
129   /** Determines whether the current location is part of a multiple char brace.
130    * @return true or false
131    */

132   public abstract boolean isMultipleCharBrace();
133
134   /** Determines whether the current location is within in gap.
135    * @return true or false
136    */

137   public abstract boolean isGap();
138
139   /** Determines whether the current location is a line comment
140    * @return true or false
141    */

142   public abstract boolean isLineComment();
143
144   /** Determines if current location is the beginning of a block comment
145    * @return true or false
146    */

147   public abstract boolean isBlockCommentStart();
148
149   /** Determines whether the current location is the end of a block comment
150    * @return boolean
151    */

152   public abstract boolean isBlockCommentEnd();
153
154   /**
155    * Determines whether the current location is a new line.
156    * @return boolean
157    */

158   public abstract boolean isNewline();
159
160   /** Returns whether the current location is a slash
161    * @return boolean
162    */

163   public abstract boolean isSlash();
164
165   /** Returns whether this is a star
166    * @return boolean
167    */

168   public abstract boolean isStar();
169
170   /** Returns whether this is a double quote
171    * @return boolean
172    */

173   public abstract boolean isDoubleQuote();
174
175   /** Returns whether this is a single quote
176    * @return boolean
177    */

178   public abstract boolean isSingleQuote();
179
180   /** Returns whether this is a double escape sequence
181    * @return boolean
182    */

183   public abstract boolean isDoubleEscapeSequence();
184
185   /** Returns whether this is a double escape
186    * @return boolean
187    */

188   public abstract boolean isDoubleEscape();
189
190   /** Returns whether this is an escaped single quote
191    * @return boolean
192    */

193   public abstract boolean isEscapedSingleQuote();
194
195   /** Return whether this is an escaped double quote
196    * @return boolean
197    */

198   public abstract boolean isEscapedDoubleQuote();
199
200   /** Increases the size of the gap.
201    * @param delta
202    */

203   public abstract void grow(int delta);
204
205   /** Decreases the size of the gap.
206    * @param delta
207    */

208   public abstract void shrink(int delta);
209
210   /** Determines whether the current location is an opening parenthesis.
211    * @return boolean
212    */

213   public abstract boolean isOpen();
214
215   /** Determines whether the current location is a closing parenthesis.
216    * @return boolean
217    */

218   public abstract boolean isClosed();
219
220   /** Determines whether the current location is an open brace.
221    * @return boolean
222    */

223   public abstract boolean isOpenBrace();
224
225   /** Determines whether the current location is a closed brace.
226    * @return boolean
227    */

228   public abstract boolean isClosedBrace();
229 }
230
231
232
233
Popular Tags