Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 483 |  | Methods: | 31
| NCLOC: | 378 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
JavaCharStream.java | 29.4% | 34.2% | 45.2% | 34.2% |

1 |  | /* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 3.0 */
2 |  | package net.sourceforge.pmd.ast;
3 |  |
4 |  | /**
5 |  | * An implementation of interface CharStream, where the stream is assumed to
6 |  | * contain only ASCII characters (with java-like unicode escape processing).
7 |  | */
8 |  |
9 |  | public class JavaCharStream implements CharStream {
10 |  | public static final boolean staticFlag = false;
11 |  |
12 | 0 | static final int hexval(char c) throws java.io.IOException {
13 | 0 | switch (c) {
14 | 0 | case '0':
15 | 0 | return 0;
16 | 0 | case '1':
17 | 0 | return 1;
18 | 0 | case '2':
19 | 0 | return 2;
20 | 0 | case '3':
21 | 0 | return 3;
22 | 0 | case '4':
23 | 0 | return 4;
24 | 0 | case '5':
25 | 0 | return 5;
26 | 0 | case '6':
27 | 0 | return 6;
28 | 0 | case '7':
29 | 0 | return 7;
30 | 0 | case '8':
31 | 0 | return 8;
32 | 0 | case '9':
33 | 0 | return 9;
34 |  |
35 | 0 | case 'a':
36 | 0 | case 'A':
37 | 0 | return 10;
38 | 0 | case 'b':
39 | 0 | case 'B':
40 | 0 | return 11;
41 | 0 | case 'c':
42 | 0 | case 'C':
43 | 0 | return 12;
44 | 0 | case 'd':
45 | 0 | case 'D':
46 | 0 | return 13;
47 | 0 | case 'e':
48 | 0 | case 'E':
49 | 0 | return 14;
50 | 0 | case 'f':
51 | 0 | case 'F':
52 | 0 | return 15;
53 |  | }
54 |  |
55 | 0 | throw new java.io.IOException(); // Should never come here
56 |  | }
57 |  |
58 |  | public int bufpos = -1;
59 |  | int bufsize;
60 |  | int available;
61 |  | int tokenBegin;
62 |  | protected int bufline[];
63 |  | protected int bufcolumn[];
64 |  |
65 |  | protected int column = 0;
66 |  | protected int line = 1;
67 |  |
68 |  | protected boolean prevCharIsCR = false;
69 |  | protected boolean prevCharIsLF = false;
70 |  |
71 |  | protected java.io.Reader inputStream;
72 |  |
73 |  | protected char[] nextCharBuf;
74 |  | protected char[] buffer;
75 |  | protected int maxNextCharInd = 0;
76 |  | protected int nextCharInd = -1;
77 |  | protected int inBuf = 0;
78 |  |
79 | 0 | protected void ExpandBuff(boolean wrapAround) {
80 | 0 | char[] newbuffer = new char[bufsize + 2048];
81 | 0 | int newbufline[] = new int[bufsize + 2048];
82 | 0 | int newbufcolumn[] = new int[bufsize + 2048];
83 |  |
84 | 0 | try {
85 | 0 | if (wrapAround) {
86 | 0 | System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
87 | 0 | System.arraycopy(buffer, 0, newbuffer,
88 |  | bufsize - tokenBegin, bufpos);
89 | 0 | buffer = newbuffer;
90 |  |
91 | 0 | System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
92 | 0 | System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
93 | 0 | bufline = newbufline;
94 |  |
95 | 0 | System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
96 | 0 | System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
97 | 0 | bufcolumn = newbufcolumn;
98 |  |
99 | 0 | bufpos += (bufsize - tokenBegin);
100 |  | } else {
101 | 0 | System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
102 | 0 | buffer = newbuffer;
103 |  |
104 | 0 | System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
105 | 0 | bufline = newbufline;
106 |  |
107 | 0 | System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
108 | 0 | bufcolumn = newbufcolumn;
109 |  |
110 | 0 | bufpos -= tokenBegin;
111 |  | }
112 |  | } catch (Throwable t) {
113 | 0 | throw new RuntimeException(t.getMessage());
114 |  | }
115 |  |
116 | 0 | available = (bufsize += 2048);
117 | 0 | tokenBegin = 0;
118 |  | }
119 |  |
120 | 4323 | protected void FillBuff() throws java.io.IOException {
121 | 4323 | int i;
122 | 4323 | if (maxNextCharInd == 4096)
123 | 0 | maxNextCharInd = nextCharInd = 0;
124 |  |
125 | 4323 | try {
126 | ? | if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
127 |  | 4096 - maxNextCharInd)) == -1) {
128 | 1453 | inputStream.close();
129 | 1453 | throw new java.io.IOException();
130 |  | } else
131 | 1461 | maxNextCharInd += i;
132 | 1461 | return;
133 |  | } catch (java.io.IOException e) {
134 | 2862 | if (bufpos != 0) {
135 | 3 | --bufpos;
136 | 3 | backup(0);
137 |  | } else {
138 | 2859 | bufline[bufpos] = line;
139 | 2859 | bufcolumn[bufpos] = column;
140 |  | }
141 | 2862 | throw e;
142 |  | }
143 |  | }
144 |  |
145 | 142310 | protected char ReadByte() throws java.io.IOException {
146 | 142310 | if (++nextCharInd >= maxNextCharInd)
147 | 4323 | FillBuff();
148 |  |
149 | 139448 | return nextCharBuf[nextCharInd];
150 |  | }
151 |  |
152 | 76401 | public char BeginToken() throws java.io.IOException {
153 | 76401 | if (inBuf > 0) {
154 | 19777 | --inBuf;
155 |  |
156 | 19777 | if (++bufpos == bufsize)
157 | 0 | bufpos = 0;
158 |  |
159 | 19777 | tokenBegin = bufpos;
160 | 19777 | return buffer[bufpos];
161 |  | }
162 |  |
163 | 56624 | tokenBegin = 0;
164 | 56624 | bufpos = -1;
165 |  |
166 | 56624 | return readChar();
167 |  | }
168 |  |
169 | 0 | protected void AdjustBuffSize() {
170 | 0 | if (available == bufsize) {
171 | 0 | if (tokenBegin > 2048) {
172 | 0 | bufpos = 0;
173 | 0 | available = tokenBegin;
174 |  | } else
175 | 0 | ExpandBuff(false);
176 | 0 | } else if (available > tokenBegin)
177 | 0 | available = bufsize;
178 | 0 | else if ((tokenBegin - available) < 2048)
179 | 0 | ExpandBuff(true);
180 |  | else
181 | 0 | available = tokenBegin;
182 |  | }
183 |  |
184 | 139448 | protected void UpdateLineColumn(char c) {
185 | 139448 | column++;
186 |  |
187 | 139448 | if (prevCharIsLF) {
188 | 6864 | prevCharIsLF = false;
189 | 6864 | line += (column = 1);
190 | 132584 | } else if (prevCharIsCR) {
191 | 0 | prevCharIsCR = false;
192 | 0 | if (c == '\n') {
193 | 0 | prevCharIsLF = true;
194 |  | } else
195 | 0 | line += (column = 1);
196 |  | }
197 |  |
198 | 139448 | switch (c) {
199 | 0 | case '\r':
200 | 0 | prevCharIsCR = true;
201 | 0 | break;
202 | 6904 | case '\n':
203 | 6904 | prevCharIsLF = true;
204 | 6904 | break;
205 | 148 | case '\t':
206 | 148 | column--;
207 | 148 | column += (8 - (column & 07));
208 | 148 | break;
209 | 132396 | default :
210 | 132396 | break;
211 |  | }
212 |  |
213 | 139448 | bufline[bufpos] = line;
214 | 139448 | bufcolumn[bufpos] = column;
215 |  | }
216 |  |
217 | 142337 | public char readChar() throws java.io.IOException {
218 | 142337 | if (inBuf > 0) {
219 | 31 | --inBuf;
220 |  |
221 | 31 | if (++bufpos == bufsize)
222 | 0 | bufpos = 0;
223 |  |
224 | 31 | return buffer[bufpos];
225 |  | }
226 |  |
227 | 142306 | char c;
228 |  |
229 | 142306 | if (++bufpos == available)
230 | 0 | AdjustBuffSize();
231 |  |
232 | ? | if ((buffer[bufpos] = c = ReadByte()) == '\\') {
233 | 4 | UpdateLineColumn(c);
234 |  |
235 | 4 | int backSlashCnt = 1;
236 |  |
237 | 4 | for (; ;) // Read all the backslashes
238 |  | {
239 | 4 | if (++bufpos == available)
240 | 0 | AdjustBuffSize();
241 |  |
242 | 4 | try {
243 | ? | if ((buffer[bufpos] = c = ReadByte()) != '\\') {
244 | 4 | UpdateLineColumn(c);
245 |  | // found a non-backslash char.
246 | 4 | if ((c == 'u') && ((backSlashCnt & 1) == 1)) {
247 | 0 | if (--bufpos < 0)
248 | 0 | bufpos = bufsize - 1;
249 |  |
250 | 0 | break;
251 |  | }
252 |  |
253 | 4 | backup(backSlashCnt);
254 | 4 | return '\\';
255 |  | }
256 |  | } catch (java.io.IOException e) {
257 | 0 | if (backSlashCnt > 1)
258 | 0 | backup(backSlashCnt);
259 |  |
260 | 0 | return '\\';
261 |  | }
262 |  |
263 | 0 | UpdateLineColumn(c);
264 | 0 | backSlashCnt++;
265 |  | }
266 |  |
267 |  | // Here, we have seen an odd number of backslash's followed by a 'u'
268 | 0 | try {
269 | 0 | while ((c = ReadByte()) == 'u')
270 | 0 | ++column;
271 |  |
272 | 0 | buffer[bufpos] = c = (char) (hexval(c) << 12 |
273 |  | hexval(ReadByte()) << 8 |
274 |  | hexval(ReadByte()) << 4 |
275 |  | hexval(ReadByte()));
276 |  |
277 | 0 | column += 4;
278 |  | } catch (java.io.IOException e) {
279 | 0 | throw new RuntimeException("Invalid escape character at line " + line +
280 |  | " column " + column + ".");
281 |  | }
282 |  |
283 | 0 | if (backSlashCnt == 1)
284 | 0 | return c;
285 |  | else {
286 | 0 | backup(backSlashCnt - 1);
287 | 0 | return '\\';
288 |  | }
289 |  | } else {
290 | 139440 | UpdateLineColumn(c);
291 | 139440 | return (c);
292 |  | }
293 |  | }
294 |  |
295 |  | /**
296 |  | * @see #getEndColumn
297 |  | * @deprecated
298 |  | */
299 |  |
300 | 0 | public int getColumn() {
301 | 0 | return bufcolumn[bufpos];
302 |  | }
303 |  |
304 |  | /**
305 |  | * @see #getEndLine
306 |  | * @deprecated
307 |  | */
308 |  |
309 | 0 | public int getLine() {
310 | 0 | return bufline[bufpos];
311 |  | }
312 |  |
313 | 76375 | public int getEndColumn() {
314 | 76375 | return bufcolumn[bufpos];
315 |  | }
316 |  |
317 | 76375 | public int getEndLine() {
318 | 76375 | return bufline[bufpos];
319 |  | }
320 |  |
321 | 76375 | public int getBeginColumn() {
322 | 76375 | return bufcolumn[tokenBegin];
323 |  | }
324 |  |
325 | 76375 | public int getBeginLine() {
326 | 76375 | return bufline[tokenBegin];
327 |  | }
328 |  |
329 | 19800 | public void backup(int amount) {
330 |  |
331 | 19800 | inBuf += amount;
332 | 19800 | if ((bufpos -= amount) < 0)
333 | 0 | bufpos += bufsize;
334 |  | }
335 |  |
336 | 1461 | public JavaCharStream(java.io.Reader dstream,
337 |  | int startline, int startcolumn, int buffersize) {
338 | 1461 | inputStream = dstream;
339 | 1461 | line = startline;
340 | 1461 | column = startcolumn - 1;
341 |  |
342 | 1461 | available = bufsize = buffersize;
343 | 1461 | buffer = new char[buffersize];
344 | 1461 | bufline = new int[buffersize];
345 | 1461 | bufcolumn = new int[buffersize];
346 | 1461 | nextCharBuf = new char[4096];
347 |  | }
348 |  |
349 | 0 | public JavaCharStream(java.io.Reader dstream,
350 |  | int startline, int startcolumn) {
351 | 0 | this(dstream, startline, startcolumn, 4096);
352 |  | }
353 |  |
354 | 1461 | public JavaCharStream(java.io.Reader dstream) {
355 | 1461 | this(dstream, 1, 1, 4096);
356 |  | }
357 |  |
358 | 0 | public void ReInit(java.io.Reader dstream,
359 |  | int startline, int startcolumn, int buffersize) {
360 | 0 | inputStream = dstream;
361 | 0 | line = startline;
362 | 0 | column = startcolumn - 1;
363 |  |
364 | 0 | if (buffer == null || buffersize != buffer.length) {
365 | 0 | available = bufsize = buffersize;
366 | 0 | buffer = new char[buffersize];
367 | 0 | bufline = new int[buffersize];
368 | 0 | bufcolumn = new int[buffersize];
369 | 0 | nextCharBuf = new char[4096];
370 |  | }
371 | 0 | prevCharIsLF = prevCharIsCR = false;
372 | 0 | tokenBegin = inBuf = maxNextCharInd = 0;
373 | 0 | nextCharInd = bufpos = -1;
374 |  | }
375 |  |
376 | 0 | public void ReInit(java.io.Reader dstream,
377 |  | int startline, int startcolumn) {
378 | 0 | ReInit(dstream, startline, startcolumn, 4096);
379 |  | }
380 |  |
381 | 0 | public void ReInit(java.io.Reader dstream) {
382 | 0 | ReInit(dstream, 1, 1, 4096);
383 |  | }
384 |  |
385 | 0 | public JavaCharStream(java.io.InputStream dstream, int startline,
386 |  | int startcolumn, int buffersize) {
387 | 0 | this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
388 |  | }
389 |  |
390 | 0 | public JavaCharStream(java.io.InputStream dstream, int startline,
391 |  | int startcolumn) {
392 | 0 | this(dstream, startline, startcolumn, 4096);
393 |  | }
394 |  |
395 | 0 | public JavaCharStream(java.io.InputStream dstream) {
396 | 0 | this(dstream, 1, 1, 4096);
397 |  | }
398 |  |
399 | 0 | public void ReInit(java.io.InputStream dstream, int startline,
400 |  | int startcolumn, int buffersize) {
401 | 0 | ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
402 |  | }
403 |  |
404 | 0 | public void ReInit(java.io.InputStream dstream, int startline,
405 |  | int startcolumn) {
406 | 0 | ReInit(dstream, startline, startcolumn, 4096);
407 |  | }
408 |  |
409 | 0 | public void ReInit(java.io.InputStream dstream) {
410 | 0 | ReInit(dstream, 1, 1, 4096);
411 |  | }
412 |  |
413 | 46968 | public String GetImage() {
414 | 46968 | if (bufpos >= tokenBegin)
415 | 46968 | return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
416 |  | else
417 | 0 | return new String(buffer, tokenBegin, bufsize - tokenBegin) +
418 |  | new String(buffer, 0, bufpos + 1);
419 |  | }
420 |  |
421 | 147 | public char[] GetSuffix(int len) {
422 | 147 | char[] ret = new char[len];
423 |  |
424 | 147 | if ((bufpos + 1) >= len)
425 | 147 | System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
426 |  | else {
427 | 0 | System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
428 |  | len - bufpos - 1);
429 | 0 | System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
430 |  | }
431 |  |
432 | 147 | return ret;
433 |  | }
434 |  |
435 | 0 | public void Done() {
436 | 0 | nextCharBuf = null;
437 | 0 | buffer = null;
438 | 0 | bufline = null;
439 | 0 | bufcolumn = null;
440 |  | }
441 |  |
442 |  | /**
443 |  | * Method to adjust line and column numbers for the start of a token.<BR>
444 |  | */
445 | 0 | public void adjustBeginLineColumn(int newLine, int newCol) {
446 | 0 | int start = tokenBegin;
447 | 0 | int len;
448 |  |
449 | 0 | if (bufpos >= tokenBegin) {
450 | 0 | len = bufpos - tokenBegin + inBuf + 1;
451 |  | } else {
452 | 0 | len = bufsize - tokenBegin + bufpos + 1 + inBuf;
453 |  | }
454 |  |
455 | 0 | int i = 0, j = 0, k = 0;
456 | 0 | int nextColDiff = 0, columnDiff = 0;
457 |  |
458 | 0 | while (i < len &&
459 |  | bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) {
460 | 0 | bufline[j] = newLine;
461 | 0 | nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
462 | 0 | bufcolumn[j] = newCol + columnDiff;
463 | 0 | columnDiff = nextColDiff;
464 | 0 | i++;
465 |  | }
466 |  |
467 | 0 | if (i < len) {
468 | 0 | bufline[j] = newLine++;
469 | 0 | bufcolumn[j] = newCol + columnDiff;
470 |  |
471 | 0 | while (i++ < len) {
472 | 0 | if (bufline[j = start % bufsize] != bufline[++start % bufsize])
473 | 0 | bufline[j] = newLine++;
474 |  | else
475 | 0 | bufline[j] = newLine;
476 |  | }
477 |  | }
478 |  |
479 | 0 | line = bufline[j];
480 | 0 | column = bufcolumn[j];
481 |  | }
482 |  |
483 |  | }