Coverage report

| %line | %branch
--- | --- | ---
org.apache.commons.jexl.parser.SimpleCharStream |
41% |
81% |

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

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