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