Clover coverage report - PMD - 3.7 Coverage timestamp: Wed May 31 2006 09:25:59 EDT 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 | 2532 | protected void FillBuff() throws java.io.IOException {
121 | 2532 | int i;
122 | 2532 | if (maxNextCharInd == 4096)
123 | 0 | maxNextCharInd = nextCharInd = 0;
124 |  |
125 | 2532 | try {
126 | ? | if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
127 |  | 4096 - maxNextCharInd)) == -1) {
128 | 1250 | inputStream.close();
129 | 1250 | throw new java.io.IOException();
130 |  | } else
131 | 1258 | maxNextCharInd += i;
132 | 1258 | return;
133 |  | } catch (java.io.IOException e) {
134 | 1274 | if (bufpos != 0) {
135 | 24 | --bufpos;
136 | 24 | backup(0);
137 |  | } else {
138 | 1250 | bufline[bufpos] = line;
139 | 1250 | bufcolumn[bufpos] = column;
140 |  | }
141 | 1274 | throw e;
142 |  | }
143 |  | }
144 |  |
145 | 120381 | protected char ReadByte() throws java.io.IOException {
146 | 120381 | if (++nextCharInd >= maxNextCharInd)
147 | 2532 | FillBuff();
148 |  |
149 | 119107 | return nextCharBuf[nextCharInd];
150 |  | }
151 |  |
152 | 64871 | public char BeginToken() throws java.io.IOException {
153 | 64871 | if (inBuf > 0) {
154 | 16866 | --inBuf;
155 |  |
156 | 16866 | if (++bufpos == bufsize)
157 | 0 | bufpos = 0;
158 |  |
159 | 16866 | tokenBegin = bufpos;
160 | 16866 | return buffer[bufpos];
161 |  | }
162 |  |
163 | 48005 | tokenBegin = 0;
164 | 48005 | bufpos = -1;
165 |  |
166 | 48005 | 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 | 119107 | protected void UpdateLineColumn(char c) {
185 | 119107 | column++;
186 |  |
187 | 119107 | if (prevCharIsLF) {
188 | 5785 | prevCharIsLF = false;
189 | 5785 | line += (column = 1);
190 | 113322 | } 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 | 119107 | switch (c) {
199 | 0 | case '\r':
200 | 0 | prevCharIsCR = true;
201 | 0 | break;
202 | 6859 | case '\n':
203 | 6859 | prevCharIsLF = true;
204 | 6859 | break;
205 | 149 | case '\t':
206 | 149 | column--;
207 | 149 | column += (8 - (column & 07));
208 | 149 | break;
209 | 112099 | default :
210 | 112099 | break;
211 |  | }
212 |  |
213 | 119107 | bufline[bufpos] = line;
214 | 119107 | bufcolumn[bufpos] = column;
215 |  | }
216 |  |
217 | 120408 | public char readChar() throws java.io.IOException {
218 | 120408 | if (inBuf > 0) {
219 | 29 | --inBuf;
220 |  |
221 | 29 | if (++bufpos == bufsize)
222 | 0 | bufpos = 0;
223 |  |
224 | 29 | return buffer[bufpos];
225 |  | }
226 |  |
227 | 120379 | char c;
228 |  |
229 | 120379 | if (++bufpos == available)
230 | 0 | AdjustBuffSize();
231 |  |
232 | ? | if ((buffer[bufpos] = c = ReadByte()) == '\\') {
233 | 2 | UpdateLineColumn(c);
234 |  |
235 | 2 | int backSlashCnt = 1;
236 |  |
237 | 2 | for (; ;) // Read all the backslashes
238 |  | {
239 | 2 | if (++bufpos == available)
240 | 0 | AdjustBuffSize();
241 |  |
242 | 2 | try {
243 | ? | if ((buffer[bufpos] = c = ReadByte()) != '\\') {
244 | 2 | UpdateLineColumn(c);
245 |  | // found a non-backslash char.
246 | 2 | if ((c == 'u') && ((backSlashCnt & 1) == 1)) {
247 | 0 | if (--bufpos < 0)
248 | 0 | bufpos = bufsize - 1;
249 |  |
250 | 0 | break;
251 |  | }
252 |  |
253 | 2 | backup(backSlashCnt);
254 | 2 | 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 | 119103 | UpdateLineColumn(c);
291 | 119103 | 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 | 64848 | public int getEndColumn() {
314 | 64848 | return bufcolumn[bufpos];
315 |  | }
316 |  |
317 | 64848 | public int getEndLine() {
318 | 64848 | return bufline[bufpos];
319 |  | }
320 |  |
321 | 64848 | public int getBeginColumn() {
322 | 64848 | return bufcolumn[tokenBegin];
323 |  | }
324 |  |
325 | 64848 | public int getBeginLine() {
326 | 64848 | return bufline[tokenBegin];
327 |  | }
328 |  |
329 | 16908 | public void backup(int amount) {
330 |  |
331 | 16908 | inBuf += amount;
332 | 16908 | if ((bufpos -= amount) < 0)
333 | 0 | bufpos += bufsize;
334 |  | }
335 |  |
336 | 1258 | public JavaCharStream(java.io.Reader dstream,
337 |  | int startline, int startcolumn, int buffersize) {
338 | 1258 | inputStream = dstream;
339 | 1258 | line = startline;
340 | 1258 | column = startcolumn - 1;
341 |  |
342 | 1258 | available = bufsize = buffersize;
343 | 1258 | buffer = new char[buffersize];
344 | 1258 | bufline = new int[buffersize];
345 | 1258 | bufcolumn = new int[buffersize];
346 | 1258 | 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 | 1258 | public JavaCharStream(java.io.Reader dstream) {
355 | 1258 | 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 | 40904 | public String GetImage() {
414 | 40904 | if (bufpos >= tokenBegin)
415 | 40904 | 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 | 5 | public char[] GetSuffix(int len) {
422 | 5 | char[] ret = new char[len];
423 |  |
424 | 5 | if ((bufpos + 1) >= len)
425 | 5 | 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 | 5 | 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 |  | }