001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.model.definitions.reducedmodel;
038:
039: /** A subclass of ReducedToken that represents sequences of non-special characters.
040: * @version $Id: Gap.java 4255 2007-08-28 19:17:37Z mgricken $
041: */
042: class Gap extends ReducedToken {
043: private int _size;
044:
045: /** Creates a new Gap.
046: * @param size the size of the gap
047: * @param state the state of the reduced model
048: */
049: Gap(int size, ReducedModelState state) {
050: super (state);
051: _size = size;
052: }
053:
054: /** Gets the size of this gap.
055: * @return _size
056: */
057: public int getSize() {
058: return _size;
059: }
060:
061: /** Gets the token type.
062: * @return the empty string
063: */
064: public String getType() {
065: return "";
066: }
067:
068: /** Blows up. The type of a Gap cannot be set.
069: * @param type the type to set to
070: * @throws RuntimeException always
071: */
072: public void setType(String type) {
073: throw new RuntimeException("Can't set type on Gap!");
074: }
075:
076: /** Blows up. A Gap cannot be flipped.
077: * @throws RuntimeException always
078: */
079: public void flip() {
080: throw new RuntimeException("Can't flip a Gap!");
081: }
082:
083: /** Increases the size of the gap.
084: * @param delta the amount by which the gap is augmented.
085: */
086: public void grow(int delta) {
087: if (delta >= 0)
088: _size += delta;
089: }
090:
091: /** Decreases the size of the gap.
092: * @param delta the amount by which the gap is diminished.
093: */
094: public void shrink(int delta) {
095: if ((delta <= _size) && (delta >= 0))
096: _size -= delta;
097: }
098:
099: /** Converts a Brace to a String. Used for debugging.
100: * @return the String representation of the Brace
101: */
102: public String toString() {
103: // String val = "Gap(size: "+_size+"): ";
104: final StringBuilder val = new StringBuilder();
105: int i;
106: for (i = 0; i < _size; i++)
107: val.append(" _");
108: return val.toString();
109: }
110:
111: /** Determines that this is not a multi-char brace.
112: * @return <code>false</code>
113: */
114: public boolean isMultipleCharBrace() {
115: return false;
116: }
117:
118: /** Determines that this is a gap.
119: * @return <code>true</code>
120: */
121: public boolean isGap() {
122: return true;
123: }
124:
125: /** Determines that this is not a line comment.
126: * @return <code>false</code>
127: */
128: public boolean isLineComment() {
129: return false;
130: }
131:
132: /** Determines that this is not the start of a block comment.
133: * @return <code>false</code>
134: */
135: public boolean isBlockCommentStart() {
136: return false;
137: }
138:
139: /** Determines that this is not the end of a block comment.
140: * @return <code>false</code>
141: */
142: public boolean isBlockCommentEnd() {
143: return false;
144: }
145:
146: /** Determines that this is not a newline.
147: * @return <code>false</code>
148: */
149: public boolean isNewline() {
150: return false;
151: }
152:
153: /** Determines that this is not a /.
154: * @return <code>false</code>
155: */
156: public boolean isSlash() {
157: return false;
158: }
159:
160: /** Determines that this is not a *.
161: * @return <code>false</code>
162: */
163: public boolean isStar() {
164: return false;
165: }
166:
167: /** Determines that this is not a ".
168: * @return <code>false</code>
169: */
170: public boolean isDoubleQuote() {
171: return false;
172: }
173:
174: /** Determines that this is not a '.
175: * @return <code>false</code>
176: */
177: public boolean isSingleQuote() {
178: return false;
179: }
180:
181: /** Determines that this is not a double escape sequence.
182: * @return <code>false</code>
183: */
184: public boolean isDoubleEscapeSequence() {
185: return false;
186: }
187:
188: /** Determines that this is not a double escape.
189: * @return <code>false</code>
190: */
191: public boolean isDoubleEscape() {
192: return false;
193: }
194:
195: /** Determines that this is not a \'.
196: * @return <code>false</code>
197: */
198: public boolean isEscapedSingleQuote() {
199: return false;
200: }
201:
202: /** Determines that this is not a \".
203: * @return <code>false</code>
204: */
205: public boolean isEscapedDoubleQuote() {
206: return false;
207: }
208:
209: /** Determines that this is not open.
210: * @return <code>false</code>
211: */
212: public boolean isOpen() {
213: return false;
214: }
215:
216: /** Determines that this is not closed. */
217: public boolean isClosed() {
218: return false;
219: }
220:
221: /** Determines that this is not a match.
222: * @param other the token to compare to
223: * @return <code>false</code>
224: */
225: public boolean isMatch(Brace other) {
226: return false;
227: }
228:
229: /** Determines that this ReducedToken is not matchable (one of "{", "}", "(", ")", "[", "]") */
230: public boolean isMatchable() {
231: return false;
232: }
233:
234: /** Determines that this is not an open brace. */
235: public boolean isOpenBrace() {
236: return false;
237: }
238:
239: /** Determines that this is not a closed brace. */
240: public boolean isClosedBrace() {
241: return false;
242: }
243: }
|