Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 483   Methods: 31
NCLOC: 378   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JavaCharStream.java 26.5% 31.7% 41.9% 31.6%
coverage coverage
 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  1852 protected void FillBuff() throws java.io.IOException {
 121  1852 int i;
 122  1852 if (maxNextCharInd == 4096)
 123  0 maxNextCharInd = nextCharInd = 0;
 124   
 125  1852 try {
 126  ? if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
 127    4096 - maxNextCharInd)) == -1) {
 128  922 inputStream.close();
 129  922 throw new java.io.IOException();
 130    } else
 131  930 maxNextCharInd += i;
 132  930 return;
 133    } catch (java.io.IOException e) {
 134  922 if (bufpos != 0) {
 135  0 --bufpos;
 136  0 backup(0);
 137    } else {
 138  922 bufline[bufpos] = line;
 139  922 bufcolumn[bufpos] = column;
 140    }
 141  922 throw e;
 142    }
 143    }
 144   
 145  78340 protected char ReadByte() throws java.io.IOException {
 146  78340 if (++nextCharInd >= maxNextCharInd)
 147  1852 FillBuff();
 148   
 149  77418 return nextCharBuf[nextCharInd];
 150    }
 151   
 152  42644 public char BeginToken() throws java.io.IOException {
 153  42644 if (inBuf > 0) {
 154  11170 --inBuf;
 155   
 156  11170 if (++bufpos == bufsize)
 157  0 bufpos = 0;
 158   
 159  11170 tokenBegin = bufpos;
 160  11170 return buffer[bufpos];
 161    }
 162   
 163  31474 tokenBegin = 0;
 164  31474 bufpos = -1;
 165   
 166  31474 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  77418 protected void UpdateLineColumn(char c) {
 185  77418 column++;
 186   
 187  77418 if (prevCharIsLF) {
 188  4077 prevCharIsLF = false;
 189  4077 line += (column = 1);
 190  73341 } 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  77418 switch (c) {
 199  0 case '\r':
 200  0 prevCharIsCR = true;
 201  0 break;
 202  4845 case '\n':
 203  4845 prevCharIsLF = true;
 204  4845 break;
 205  122 case '\t':
 206  122 column--;
 207  122 column += (8 - (column & 07));
 208  122 break;
 209  72451 default :
 210  72451 break;
 211    }
 212   
 213  77418 bufline[bufpos] = line;
 214  77418 bufcolumn[bufpos] = column;
 215    }
 216   
 217  78343 public char readChar() throws java.io.IOException {
 218  78343 if (inBuf > 0) {
 219  4 --inBuf;
 220   
 221  4 if (++bufpos == bufsize)
 222  0 bufpos = 0;
 223   
 224  4 return buffer[bufpos];
 225    }
 226   
 227  78339 char c;
 228   
 229  78339 if (++bufpos == available)
 230  0 AdjustBuffSize();
 231   
 232  ? if ((buffer[bufpos] = c = ReadByte()) == '\\') {
 233  1 UpdateLineColumn(c);
 234   
 235  1 int backSlashCnt = 1;
 236   
 237  1 for (; ;) // Read all the backslashes
 238    {
 239  1 if (++bufpos == available)
 240  0 AdjustBuffSize();
 241   
 242  1 try {
 243  ? if ((buffer[bufpos] = c = ReadByte()) != '\\') {
 244  1 UpdateLineColumn(c);
 245    // found a non-backslash char.
 246  1 if ((c == 'u') && ((backSlashCnt & 1) == 1)) {
 247  0 if (--bufpos < 0)
 248  0 bufpos = bufsize - 1;
 249   
 250  0 break;
 251    }
 252   
 253  1 backup(backSlashCnt);
 254  1 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  77416 UpdateLineColumn(c);
 291  77416 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  42644 public int getEndColumn() {
 314  42644 return bufcolumn[bufpos];
 315    }
 316   
 317  42644 public int getEndLine() {
 318  42644 return bufline[bufpos];
 319    }
 320   
 321  42644 public int getBeginColumn() {
 322  42644 return bufcolumn[tokenBegin];
 323    }
 324   
 325  42644 public int getBeginLine() {
 326  42644 return bufline[tokenBegin];
 327    }
 328   
 329  11178 public void backup(int amount) {
 330   
 331  11178 inBuf += amount;
 332  11178 if ((bufpos -= amount) < 0)
 333  0 bufpos += bufsize;
 334    }
 335   
 336  930 public JavaCharStream(java.io.Reader dstream,
 337    int startline, int startcolumn, int buffersize) {
 338  930 inputStream = dstream;
 339  930 line = startline;
 340  930 column = startcolumn - 1;
 341   
 342  930 available = bufsize = buffersize;
 343  930 buffer = new char[buffersize];
 344  930 bufline = new int[buffersize];
 345  930 bufcolumn = new int[buffersize];
 346  930 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  930 public JavaCharStream(java.io.Reader dstream) {
 355  930 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  26346 public String GetImage() {
 414  26346 if (bufpos >= tokenBegin)
 415  26346 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  0 public char[] GetSuffix(int len) {
 422  0 char[] ret = new char[len];
 423   
 424  0 if ((bufpos + 1) >= len)
 425  0 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  0 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    }