Coverage report

| %line | %branch
--- | --- | ---
org.apache.commons.jexl.parser.SimpleCharStream |
40% |
80% |

1 |  |
     /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 2.1 */
2 |  |
     package org.apache.commons.jexl.parser;
3 |  |
4 |  |
     /**
5 |  |
      * An implementation of interface CharStream, where the stream is assumed to
6 |  |
      * contain only ASCII characters (without unicode processing).
7 |  |
      */
8 |  |
9 |  |
     public final class SimpleCharStream
10 |  |
     {
11 |  |
       public static final boolean class="keyword">staticFlag = false;
12 |  |
       int bufsize;
13 |  |
       int available;
14 |  |
       int tokenBegin;
15 | 75 |
       public int bufpos = -1;
16 |  |
       private int bufline[];
17 |  |
       private int bufcolumn[];
18 |  |
19 | 75 |
       private int column = 0;
20 | 75 |
       private int line = 1;
21 |  |
22 | 75 |
       private boolean prevCharIsCR = false;
23 | 75 |
       private boolean prevCharIsLF = false;
24 |  |
25 |  |
       private java.io.Reader inputStream;
26 |  |
27 |  |
       private char[] buffer;
28 | 75 |
       private int maxNextCharInd = 0;
29 | 75 |
       private int inBuf = 0;
30 |  |
31 |  |
       private final void ExpandBuff(boolean wrapAround)
32 |  |
       {
33 | 0 |
          char[] newbuffer = new class="keyword">char[bufsize + 2048];
34 | 0 |
          int newbufline[] = new class="keyword">int[bufsize + 2048];
35 | 0 |
          int newbufcolumn[] = new class="keyword">int[bufsize + 2048];
36 |  |
37 |  |
          try
38 |  |
          {
39 | 0 |
             if (wrapAround)
40 |  |
             {
41 | 0 |
                System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
42 | 0 |
                System.arraycopy(buffer, 0, newbuffer,
43 |  |
                                                  bufsize - tokenBegin, bufpos);
44 | 0 |
                buffer = newbuffer;
45 |  |
46 | 0 |
                System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
47 | 0 |
                System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
48 | 0 |
                bufline = newbufline;
49 |  |
50 | 0 |
                System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
51 | 0 |
                System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
52 | 0 |
                bufcolumn = newbufcolumn;
53 |  |
54 | 0 |
                maxNextCharInd = (bufpos += (bufsize - tokenBegin));
55 |  |
             }
56 |  |
             else
57 |  |
             {
58 | 0 |
                System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
59 | 0 |
                buffer = newbuffer;
60 |  |
61 | 0 |
                System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
62 | 0 |
                bufline = newbufline;
63 |  |
64 | 0 |
                System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
65 | 0 |
                bufcolumn = newbufcolumn;
66 |  |
67 | 0 |
                maxNextCharInd = (bufpos -= tokenBegin);
68 |  |
             }
69 | 0 |
          }
70 |  |
          catch (Throwable t)
71 |  |
          {
72 | 0 |
             throw new Error(t.getMessage());
73 |  |
          }
74 |  |
75 |  |
76 | 0 |
          bufsize += 2048;
77 | 0 |
          available = bufsize;
78 | 0 |
          tokenBegin = 0;
79 | 0 |
       }
80 |  |
81 |  |
       private final void FillBuff() throws java.io.IOException
82 |  |
       {
83 | 5601 |
          if (maxNextCharInd == available)
84 |  |
          {
85 | 0 |
             if (available == bufsize)
86 |  |
             {
87 | 0 |
                if (tokenBegin > 2048)
88 |  |
                {
89 | 0 |
                   bufpos = maxNextCharInd = 0;
90 | 0 |
                   available = tokenBegin;
91 |  |
                }
92 | 0 |
                else if (tokenBegin < 0)
93 | 0 |
                   bufpos = maxNextCharInd = 0;
94 |  |
                else
95 | 0 |
                   ExpandBuff(false);
96 |  |
             }
97 | 0 |
             else if (available > tokenBegin)
98 | 0 |
                available = bufsize;
99 | 0 |
             else if ((tokenBegin - available) < 2048)
100 | 0 |
                ExpandBuff(true);
101 |  |
             else
102 | 0 |
                available = tokenBegin;
103 |  |
          }
104 |  |
105 |  |
          int i;
106 |  |
          try {
107 | 6367 |
             if ((i = inputStream.read(buffer, maxNextCharInd,
108 | 766 |
                                         available - maxNextCharInd)) == -1)
109 |  |
             {
110 | 2793 |
                inputStream.close();
111 | 2793 |
                throw new java.io.IOException();
112 |  |
             }
113 |  |
             else
114 | 2808 |
                maxNextCharInd += i;
115 | 2808 |
             return;
116 |  |
          }
117 | 947 |
          catch(java.io.IOException e) {
118 | 2793 |
             --bufpos;
119 | 2793 |
             backup(0);
120 | 2793 |
             if (tokenBegin == -1)
121 | 2793 |
                tokenBegin = bufpos;
122 | 2793 |
             throw e;
123 |  |
          }
124 |  |
       }
125 |  |
126 |  |
       public final char BeginToken() throws java.io.IOException
127 |  |
       {
128 | 22080 |
          tokenBegin = -1;
129 | 22080 |
          char c = readChar();
130 | 19287 |
          tokenBegin = bufpos;
131 |  |
132 | 19287 |
          return c;
133 |  |
       }
134 |  |
135 |  |
       private final void UpdateLineColumn(char c)
136 |  |
       {
137 | 40440 |
          column++;
138 |  |
139 | 40440 |
          if (prevCharIsLF)
140 |  |
          {
141 | 15 |
             prevCharIsLF = false;
142 | 15 |
             line += (column = 1);
143 |  |
          }
144 | 40425 |
          else if (prevCharIsCR)
145 |  |
          {
146 | 0 |
             prevCharIsCR = false;
147 | 0 |
             if (c == '\n')
148 |  |
             {
149 | 0 |
                prevCharIsLF = true;
150 |  |
             }
151 |  |
             else
152 | 0 |
                line += (column = 1);
153 |  |
          }
154 |  |
155 | 40440 |
          switch (c)
156 |  |
          {
157 |  |
             case '\r' :
158 | 0 |
                prevCharIsCR = true;
159 | 0 |
                break;
160 |  |
             case '\n' :
161 | 15 |
                prevCharIsLF = true;
162 | 15 |
                break;
163 |  |
             case '\t' :
164 | 0 |
                column--;
165 | 0 |
                column += (8 - (column & 07));
166 | 0 |
                break;
167 |  |
             default :
168 |  |
                break;
169 |  |
          }
170 |  |
171 | 40440 |
          bufline[bufpos] = line;
172 | 40440 |
          bufcolumn[bufpos] = column;
173 | 40440 |
       }
174 |  |
175 |  |
       public final char readChar() throws java.io.IOException
176 |  |
       {
177 | 49896 |
          if (inBuf > 0)
178 |  |
          {
179 | 6663 |
             --inBuf;
180 |  |
181 | 6663 |
             if (++bufpos == bufsize)
182 | 0 |
                bufpos = 0;
183 |  |
184 | 6663 |
             return buffer[bufpos];
185 |  |
          }
186 |  |
187 | 43233 |
          if (++bufpos >= maxNextCharInd)
188 | 5601 |
             FillBuff();
189 |  |
190 | 40440 |
          char c = buffer[bufpos];
191 |  |
192 | 40440 |
          UpdateLineColumn(c);
193 | 40440 |
          return (c);
194 |  |
       }
195 |  |
196 |  |
       /**
197 |  |
        * @deprecated
198 |  |
        * @see #getEndColumn
199 |  |
        */
200 |  |
201 |  |
       public final int getColumn() {
202 | 0 |
          return bufcolumn[bufpos];
203 |  |
       }
204 |  |
205 |  |
       /**
206 |  |
        * @deprecated
207 |  |
        * @see #getEndLine
208 |  |
        */
209 |  |
210 |  |
       public final int getLine() {
211 | 0 |
          return bufline[bufpos];
212 |  |
       }
213 |  |
214 |  |
       public final int getEndColumn() {
215 | 18264 |
          return bufcolumn[bufpos];
216 |  |
       }
217 |  |
218 |  |
       public final int getEndLine() {
219 | 18264 |
          return bufline[bufpos];
220 |  |
       }
221 |  |
222 |  |
       public final int getBeginColumn() {
223 | 18264 |
          return bufcolumn[tokenBegin];
224 |  |
       }
225 |  |
226 |  |
       public final int getBeginLine() {
227 | 18264 |
          return bufline[tokenBegin];
228 |  |
       }
229 |  |
230 |  |
       public final void backup(int amount) {
231 |  |
232 | 24942 |
         inBuf += amount;
233 | 24942 |
         if ((bufpos -= amount) < 0)
234 | 0 |
            bufpos += bufsize;
235 | 24942 |
       }
236 |  |
237 | 5 |
       public SimpleCharStream(java.io.Reader dstream, int startline,
238 |  |
       int startcolumn, class="keyword">int buffersize)
239 | 70 |
       {
240 | 75 |
         inputStream = dstream;
241 | 75 |
         line = startline;
242 | 75 |
         column = startcolumn - 1;
243 |  |
244 | 75 |
         available = bufsize = buffersize;
245 | 75 |
         buffer = new char[buffersize];
246 | 75 |
         bufline = new int[buffersize];
247 | 75 |
         bufcolumn = new int[buffersize];
248 | 75 |
       }
249 |  |
250 |  |
       public SimpleCharStream(java.io.Reader dstream, int startline,
251 |  |
                                                                int startcolumn)
252 |  |
       {
253 | 75 |
          this(dstream, startline, startcolumn, 4096);
254 | 75 |
       }
255 |  |
256 |  |
       public SimpleCharStream(java.io.Reader dstream)
257 |  |
       {
258 | 0 |
          this(dstream, 1, 1, 4096);
259 | 0 |
       }
260 |  |
       public void ReInit(java.io.Reader dstream, int startline,
261 |  |
       int startcolumn, class="keyword">int buffersize)
262 |  |
       {
263 | 2808 |
         inputStream = dstream;
264 | 2808 |
         line = startline;
265 | 2808 |
         column = startcolumn - 1;
266 |  |
267 | 2808 |
         if (buffer == null || buffersize != buffer.length)
268 |  |
         {
269 | 0 |
           available = bufsize = buffersize;
270 | 0 |
           buffer = new char[buffersize];
271 | 0 |
           bufline = new int[buffersize];
272 | 0 |
           bufcolumn = new int[buffersize];
273 |  |
         }
274 | 2808 |
         prevCharIsLF = prevCharIsCR = false;
275 | 2808 |
         tokenBegin = inBuf = maxNextCharInd = 0;
276 | 2808 |
         bufpos = -1;
277 | 2808 |
       }
278 |  |
279 |  |
       public void ReInit(java.io.Reader dstream, int startline,
280 |  |
                                                                int startcolumn)
281 |  |
       {
282 | 2808 |
          ReInit(dstream, startline, startcolumn, 4096);
283 | 2808 |
       }
284 |  |
285 |  |
       public void ReInit(java.io.Reader dstream)
286 |  |
       {
287 | 0 |
          ReInit(dstream, 1, 1, 4096);
288 | 0 |
       }
289 |  |
       public SimpleCharStream(java.io.InputStream dstream, int startline,
290 |  |
       int startcolumn, class="keyword">int buffersize)
291 |  |
       {
292 | 0 |
          this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
293 | 0 |
       }
294 |  |
295 |  |
       public SimpleCharStream(java.io.InputStream dstream, int startline,
296 |  |
                                                                int startcolumn)
297 |  |
       {
298 | 0 |
          this(dstream, startline, startcolumn, 4096);
299 | 0 |
       }
300 |  |
301 |  |
       public SimpleCharStream(java.io.InputStream dstream)
302 |  |
       {
303 | 0 |
          this(dstream, 1, 1, 4096);
304 | 0 |
       }
305 |  |
306 |  |
       public void ReInit(java.io.InputStream dstream, int startline,
307 |  |
                               int startcolumn, class="keyword">int buffersize)
308 |  |
       {
309 | 0 |
          ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
310 | 0 |
       }
311 |  |
312 |  |
       public void ReInit(java.io.InputStream dstream)
313 |  |
       {
314 | 0 |
          ReInit(dstream, 1, 1, 4096);
315 | 0 |
       }
316 |  |
       public void ReInit(java.io.InputStream dstream, int startline,
317 |  |
                                                                int startcolumn)
318 |  |
       {
319 | 0 |
          ReInit(dstream, startline, startcolumn, 4096);
320 | 0 |
       }
321 |  |
       public final String GetImage()
322 |  |
       {
323 | 6123 |
          if (bufpos >= tokenBegin)
324 | 6123 |
             return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
325 |  |
          else
326 | 0 |
             return new String(buffer, tokenBegin, bufsize - tokenBegin) +
327 |  |
                                   new String(buffer, 0, bufpos + 1);
328 |  |
       }
329 |  |
330 |  |
       public final char[] GetSuffix(int len)
331 |  |
       {
332 | 0 |
          char[] ret = new class="keyword">char[len];
333 |  |
334 | 0 |
          if ((bufpos + 1) >= len)
335 | 0 |
             System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
336 |  |
          else
337 |  |
          {
338 | 0 |
             System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
339 |  |
                                                               len - bufpos - 1);
340 | 0 |
             System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
341 |  |
          }
342 |  |
343 | 0 |
          return ret;
344 |  |
       }
345 |  |
346 |  |
       public void Done()
347 |  |
       {
348 | 0 |
          buffer = null;
349 | 0 |
          bufline = null;
350 | 0 |
          bufcolumn = null;
351 | 0 |
       }
352 |  |
353 |  |
       /**
354 |  |
        * Method to adjust line and column numbers for the start of a token.<BR>
355 |  |
        */
356 |  |
       public void adjustBeginLineColumn(int newLine, class="keyword">int newCol)
357 |  |
       {
358 | 0 |
          int start = tokenBegin;
359 |  |
          int len;
360 |  |
361 | 0 |
          if (bufpos >= tokenBegin)
362 |  |
          {
363 | 0 |
             len = bufpos - tokenBegin + inBuf + 1;
364 |  |
          }
365 |  |
          else
366 |  |
          {
367 | 0 |
             len = bufsize - tokenBegin + bufpos + 1 + inBuf;
368 |  |
          }
369 |  |
370 | 0 |
          int i = 0, j = 0, k = 0;
371 | 0 |
          int nextColDiff = 0, columnDiff = 0;
372 |  |
373 | 0 |
          while (i < len &&
374 | 0 |
                 bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
375 |  |
          {
376 | 0 |
             bufline[j] = newLine;
377 | 0 |
             nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
378 | 0 |
             bufcolumn[j] = newCol + columnDiff;
379 | 0 |
             columnDiff = nextColDiff;
380 | 0 |
             i++;
381 |  |
          }
382 |  |
383 | 0 |
          if (i < len)
384 |  |
          {
385 | 0 |
             bufline[j] = newLine++;
386 | 0 |
             bufcolumn[j] = newCol + columnDiff;
387 |  |
388 | 0 |
             while (i++ < len)
389 |  |
             {
390 | 0 |
                if (bufline[j = start % bufsize] != bufline[++start % bufsize])
391 | 0 |
                   bufline[j] = newLine++;
392 |  |
                else
393 | 0 |
                   bufline[j] = newLine;
394 |  |
             }
395 |  |
          }
396 |  |
397 | 0 |
          line = bufline[j];
398 | 0 |
          column = bufcolumn[j];
399 | 0 |
       }
400 |  |
401 |  |
     }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.