Clover coverage report - DynamicJava Test Coverage (dynamicjava-20130615-r5436)
Coverage timestamp: Sat Jun 15 2013 03:01:32 CDT
file stats: LOC: 584   Methods: 39
NCLOC: 478   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JavaCharStream.java 20.8% 24.6% 33.3% 24.8%
coverage coverage
 1    /* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 4.0 */
 2    package koala.dynamicjava.parser.impl;
 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
 10    {
 11    public static final boolean staticFlag = false;
 12  0 static final int hexval(char c) throws java.io.IOException {
 13  0 switch(c)
 14    {
 15  0 case '0' :
 16  0 return 0;
 17  0 case '1' :
 18  0 return 1;
 19  0 case '2' :
 20  0 return 2;
 21  0 case '3' :
 22  0 return 3;
 23  0 case '4' :
 24  0 return 4;
 25  0 case '5' :
 26  0 return 5;
 27  0 case '6' :
 28  0 return 6;
 29  0 case '7' :
 30  0 return 7;
 31  0 case '8' :
 32  0 return 8;
 33  0 case '9' :
 34  0 return 9;
 35   
 36  0 case 'a' :
 37  0 case 'A' :
 38  0 return 10;
 39  0 case 'b' :
 40  0 case 'B' :
 41  0 return 11;
 42  0 case 'c' :
 43  0 case 'C' :
 44  0 return 12;
 45  0 case 'd' :
 46  0 case 'D' :
 47  0 return 13;
 48  0 case 'e' :
 49  0 case 'E' :
 50  0 return 14;
 51  0 case 'f' :
 52  0 case 'F' :
 53  0 return 15;
 54    }
 55   
 56  0 throw new java.io.IOException(); // Should never come here
 57    }
 58   
 59    public int bufpos = -1;
 60    int bufsize;
 61    int available;
 62    int tokenBegin;
 63    protected int bufline[];
 64    protected int bufcolumn[];
 65   
 66    protected int column = 0;
 67    protected int line = 1;
 68   
 69    protected boolean prevCharIsCR = false;
 70    protected boolean prevCharIsLF = false;
 71   
 72    protected java.io.Reader inputStream;
 73   
 74    protected char[] nextCharBuf;
 75    protected char[] buffer;
 76    protected int maxNextCharInd = 0;
 77    protected int nextCharInd = -1;
 78    protected int inBuf = 0;
 79    protected int tabSize = 8;
 80   
 81  0 protected void setTabSize(int i) { tabSize = i; }
 82  0 protected int getTabSize(int i) { return tabSize; }
 83   
 84  0 protected void ExpandBuff(boolean wrapAround)
 85    {
 86  0 char[] newbuffer = new char[bufsize + 2048];
 87  0 int newbufline[] = new int[bufsize + 2048];
 88  0 int newbufcolumn[] = new int[bufsize + 2048];
 89   
 90  0 try
 91    {
 92  0 if (wrapAround)
 93    {
 94  0 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
 95  0 System.arraycopy(buffer, 0, newbuffer,
 96    bufsize - tokenBegin, bufpos);
 97  0 buffer = newbuffer;
 98   
 99  0 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
 100  0 System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
 101  0 bufline = newbufline;
 102   
 103  0 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
 104  0 System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
 105  0 bufcolumn = newbufcolumn;
 106   
 107  0 bufpos += (bufsize - tokenBegin);
 108    }
 109    else
 110    {
 111  0 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
 112  0 buffer = newbuffer;
 113   
 114  0 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
 115  0 bufline = newbufline;
 116   
 117  0 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
 118  0 bufcolumn = newbufcolumn;
 119   
 120  0 bufpos -= tokenBegin;
 121    }
 122    }
 123    catch (Throwable t)
 124    {
 125  0 throw new Error(t.getMessage());
 126    }
 127   
 128  0 available = (bufsize += 2048);
 129  0 tokenBegin = 0;
 130    }
 131   
 132  1438 protected void FillBuff() throws java.io.IOException
 133    {
 134  1438 int i;
 135  1438 if (maxNextCharInd == 4096)
 136  0 maxNextCharInd = nextCharInd = 0;
 137   
 138  1438 try {
 139  ? if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
 140    4096 - maxNextCharInd)) == -1)
 141    {
 142  793 inputStream.close();
 143  793 throw new java.io.IOException();
 144    }
 145    else
 146  436 maxNextCharInd += i;
 147  436 return;
 148    }
 149    catch(java.io.IOException e) {
 150  1002 if (bufpos != 0)
 151    {
 152  9 --bufpos;
 153  9 backup(0);
 154    }
 155    else
 156    {
 157  993 bufline[bufpos] = line;
 158  993 bufcolumn[bufpos] = column;
 159    }
 160  1002 throw e;
 161    }
 162    }
 163   
 164  69359 protected char ReadByte() throws java.io.IOException
 165    {
 166  69359 if (++nextCharInd >= maxNextCharInd)
 167  1438 FillBuff();
 168   
 169  68357 return nextCharBuf[nextCharInd];
 170    }
 171   
 172  35798 public char BeginToken() throws java.io.IOException
 173    {
 174  35798 if (inBuf > 0)
 175    {
 176  12321 --inBuf;
 177   
 178  12321 if (++bufpos == bufsize)
 179  0 bufpos = 0;
 180   
 181  12321 tokenBegin = bufpos;
 182  12321 return buffer[bufpos];
 183    }
 184   
 185  23477 tokenBegin = 0;
 186  23477 bufpos = -1;
 187   
 188  23477 return readChar();
 189    }
 190   
 191  0 protected void AdjustBuffSize()
 192    {
 193  0 if (available == bufsize)
 194    {
 195  0 if (tokenBegin > 2048)
 196    {
 197  0 bufpos = 0;
 198  0 available = tokenBegin;
 199    }
 200    else
 201  0 ExpandBuff(false);
 202    }
 203  0 else if (available > tokenBegin)
 204  0 available = bufsize;
 205  0 else if ((tokenBegin - available) < 2048)
 206  0 ExpandBuff(true);
 207    else
 208  0 available = tokenBegin;
 209    }
 210   
 211  68357 protected void UpdateLineColumn(char c)
 212    {
 213  68357 column++;
 214   
 215  68357 if (prevCharIsLF)
 216    {
 217  1793 prevCharIsLF = false;
 218  1793 line += (column = 1);
 219    }
 220  66564 else if (prevCharIsCR)
 221    {
 222  0 prevCharIsCR = false;
 223  0 if (c == '\n')
 224    {
 225  0 prevCharIsLF = true;
 226    }
 227    else
 228  0 line += (column = 1);
 229    }
 230   
 231  68357 switch (c)
 232    {
 233  0 case '\r' :
 234  0 prevCharIsCR = true;
 235  0 break;
 236  1985 case '\n' :
 237  1985 prevCharIsLF = true;
 238  1985 break;
 239  0 case '\t' :
 240  0 column--;
 241  0 column += (tabSize - (column % tabSize));
 242  0 break;
 243  66372 default :
 244  66372 break;
 245    }
 246   
 247  68357 bufline[bufpos] = line;
 248  68357 bufcolumn[bufpos] = column;
 249    }
 250   
 251  69359 public char readChar() throws java.io.IOException
 252    {
 253  69359 if (inBuf > 0)
 254    {
 255  0 --inBuf;
 256   
 257  0 if (++bufpos == bufsize)
 258  0 bufpos = 0;
 259   
 260  0 return buffer[bufpos];
 261    }
 262   
 263  69359 char c;
 264   
 265  69359 if (++bufpos == available)
 266  0 AdjustBuffSize();
 267   
 268  ? if ((buffer[bufpos] = c = ReadByte()) == '\\')
 269    {
 270  0 UpdateLineColumn(c);
 271   
 272  0 int backSlashCnt = 1;
 273   
 274  0 for (;;) // Read all the backslashes
 275    {
 276  0 if (++bufpos == available)
 277  0 AdjustBuffSize();
 278   
 279  0 try
 280    {
 281  0 if ((buffer[bufpos] = c = ReadByte()) != '\\')
 282    {
 283  0 UpdateLineColumn(c);
 284    // found a non-backslash char.
 285  0 if ((c == 'u') && ((backSlashCnt & 1) == 1))
 286    {
 287  0 if (--bufpos < 0)
 288  0 bufpos = bufsize - 1;
 289   
 290  0 break;
 291    }
 292   
 293  0 backup(backSlashCnt);
 294  0 return '\\';
 295    }
 296    }
 297    catch(java.io.IOException e)
 298    {
 299  0 if (backSlashCnt > 1)
 300  0 backup(backSlashCnt);
 301   
 302  0 return '\\';
 303    }
 304   
 305  0 UpdateLineColumn(c);
 306  0 backSlashCnt++;
 307    }
 308   
 309    // Here, we have seen an odd number of backslash's followed by a 'u'
 310  0 try
 311    {
 312  0 while ((c = ReadByte()) == 'u')
 313  0 ++column;
 314   
 315  0 buffer[bufpos] = c = (char)(hexval(c) << 12 |
 316    hexval(ReadByte()) << 8 |
 317    hexval(ReadByte()) << 4 |
 318    hexval(ReadByte()));
 319   
 320  0 column += 4;
 321    }
 322    catch(java.io.IOException e)
 323    {
 324  0 throw new Error("Invalid escape character at line " + line +
 325    " column " + column + ".");
 326    }
 327   
 328  0 if (backSlashCnt == 1)
 329  0 return c;
 330    else
 331    {
 332  0 backup(backSlashCnt - 1);
 333  0 return '\\';
 334    }
 335    }
 336    else
 337    {
 338  68357 UpdateLineColumn(c);
 339  68357 return (c);
 340    }
 341    }
 342   
 343    /**
 344    * @deprecated
 345    * @see #getEndColumn
 346    */
 347   
 348  0 public int getColumn() {
 349  0 return bufcolumn[bufpos];
 350    }
 351   
 352    /**
 353    * @deprecated
 354    * @see #getEndLine
 355    */
 356   
 357  0 public int getLine() {
 358  0 return bufline[bufpos];
 359    }
 360   
 361  20514 public int getEndColumn() {
 362  20514 return bufcolumn[bufpos];
 363    }
 364   
 365  20514 public int getEndLine() {
 366  20514 return bufline[bufpos];
 367    }
 368   
 369  20514 public int getBeginColumn() {
 370  20514 return bufcolumn[tokenBegin];
 371    }
 372   
 373  20514 public int getBeginLine() {
 374  20514 return bufline[tokenBegin];
 375    }
 376   
 377  32251 public void backup(int amount) {
 378   
 379  32251 inBuf += amount;
 380  32251 if ((bufpos -= amount) < 0)
 381  0 bufpos += bufsize;
 382    }
 383   
 384  793 public JavaCharStream(java.io.Reader dstream,
 385    int startline, int startcolumn, int buffersize)
 386    {
 387  793 inputStream = dstream;
 388  793 line = startline;
 389  793 column = startcolumn - 1;
 390   
 391  793 available = bufsize = buffersize;
 392  793 buffer = new char[buffersize];
 393  793 bufline = new int[buffersize];
 394  793 bufcolumn = new int[buffersize];
 395  793 nextCharBuf = new char[4096];
 396    }
 397   
 398  793 public JavaCharStream(java.io.Reader dstream,
 399    int startline, int startcolumn)
 400    {
 401  793 this(dstream, startline, startcolumn, 4096);
 402    }
 403   
 404  0 public JavaCharStream(java.io.Reader dstream)
 405    {
 406  0 this(dstream, 1, 1, 4096);
 407    }
 408  0 public void ReInit(java.io.Reader dstream,
 409    int startline, int startcolumn, int buffersize)
 410    {
 411  0 inputStream = dstream;
 412  0 line = startline;
 413  0 column = startcolumn - 1;
 414   
 415  0 if (buffer == null || buffersize != buffer.length)
 416    {
 417  0 available = bufsize = buffersize;
 418  0 buffer = new char[buffersize];
 419  0 bufline = new int[buffersize];
 420  0 bufcolumn = new int[buffersize];
 421  0 nextCharBuf = new char[4096];
 422    }
 423  0 prevCharIsLF = prevCharIsCR = false;
 424  0 tokenBegin = inBuf = maxNextCharInd = 0;
 425  0 nextCharInd = bufpos = -1;
 426    }
 427   
 428  0 public void ReInit(java.io.Reader dstream,
 429    int startline, int startcolumn)
 430    {
 431  0 ReInit(dstream, startline, startcolumn, 4096);
 432    }
 433   
 434  0 public void ReInit(java.io.Reader dstream)
 435    {
 436  0 ReInit(dstream, 1, 1, 4096);
 437    }
 438  0 public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
 439    int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
 440    {
 441  0 this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
 442    }
 443   
 444  0 public JavaCharStream(java.io.InputStream dstream, int startline,
 445    int startcolumn, int buffersize)
 446    {
 447  0 this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
 448    }
 449   
 450  0 public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
 451    int startcolumn) throws java.io.UnsupportedEncodingException
 452    {
 453  0 this(dstream, encoding, startline, startcolumn, 4096);
 454    }
 455   
 456  0 public JavaCharStream(java.io.InputStream dstream, int startline,
 457    int startcolumn)
 458    {
 459  0 this(dstream, startline, startcolumn, 4096);
 460    }
 461   
 462  0 public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
 463    {
 464  0 this(dstream, encoding, 1, 1, 4096);
 465    }
 466   
 467  0 public JavaCharStream(java.io.InputStream dstream)
 468    {
 469  0 this(dstream, 1, 1, 4096);
 470    }
 471   
 472  0 public void ReInit(java.io.InputStream dstream, String encoding, int startline,
 473    int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
 474    {
 475  0 ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
 476    }
 477   
 478  0 public void ReInit(java.io.InputStream dstream, int startline,
 479    int startcolumn, int buffersize)
 480    {
 481  0 ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
 482    }
 483  0 public void ReInit(java.io.InputStream dstream, String encoding, int startline,
 484    int startcolumn) throws java.io.UnsupportedEncodingException
 485    {
 486  0 ReInit(dstream, encoding, startline, startcolumn, 4096);
 487    }
 488  0 public void ReInit(java.io.InputStream dstream, int startline,
 489    int startcolumn)
 490    {
 491  0 ReInit(dstream, startline, startcolumn, 4096);
 492    }
 493  0 public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
 494    {
 495  0 ReInit(dstream, encoding, 1, 1, 4096);
 496    }
 497   
 498  0 public void ReInit(java.io.InputStream dstream)
 499    {
 500  0 ReInit(dstream, 1, 1, 4096);
 501    }
 502   
 503  6847 public String GetImage()
 504    {
 505  6847 if (bufpos >= tokenBegin)
 506  6847 return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
 507    else
 508  0 return new String(buffer, tokenBegin, bufsize - tokenBegin) +
 509    new String(buffer, 0, bufpos + 1);
 510    }
 511   
 512  0 public char[] GetSuffix(int len)
 513    {
 514  0 char[] ret = new char[len];
 515   
 516  0 if ((bufpos + 1) >= len)
 517  0 System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
 518    else
 519    {
 520  0 System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
 521    len - bufpos - 1);
 522  0 System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
 523    }
 524   
 525  0 return ret;
 526    }
 527   
 528  0 public void Done()
 529    {
 530  0 nextCharBuf = null;
 531  0 buffer = null;
 532  0 bufline = null;
 533  0 bufcolumn = null;
 534    }
 535   
 536    /**
 537    * Method to adjust line and column numbers for the start of a token.
 538    */
 539  0 public void adjustBeginLineColumn(int newLine, int newCol)
 540    {
 541  0 int start = tokenBegin;
 542  0 int len;
 543   
 544  0 if (bufpos >= tokenBegin)
 545    {
 546  0 len = bufpos - tokenBegin + inBuf + 1;
 547    }
 548    else
 549    {
 550  0 len = bufsize - tokenBegin + bufpos + 1 + inBuf;
 551    }
 552   
 553  0 int i = 0, j = 0, k = 0;
 554  0 int nextColDiff = 0, columnDiff = 0;
 555   
 556  0 while (i < len &&
 557    bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
 558    {
 559  0 bufline[j] = newLine;
 560  0 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
 561  0 bufcolumn[j] = newCol + columnDiff;
 562  0 columnDiff = nextColDiff;
 563  0 i++;
 564    }
 565   
 566  0 if (i < len)
 567    {
 568  0 bufline[j] = newLine++;
 569  0 bufcolumn[j] = newCol + columnDiff;
 570   
 571  0 while (i++ < len)
 572    {
 573  0 if (bufline[j = start % bufsize] != bufline[++start % bufsize])
 574  0 bufline[j] = newLine++;
 575    else
 576  0 bufline[j] = newLine;
 577    }
 578    }
 579   
 580  0 line = bufline[j];
 581  0 column = bufcolumn[j];
 582    }
 583   
 584    }