1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.base.io; |
17 |
|
|
18 |
|
import java.io.File; |
19 |
|
import java.io.IOException; |
20 |
|
import java.io.InputStream; |
21 |
|
import java.io.Reader; |
22 |
|
import java.math.BigInteger; |
23 |
|
|
24 |
|
import org.qedeq.base.utility.StringUtility; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@author |
31 |
|
|
|
|
| 77.5% |
Uncovered Elements: 110 (489) |
Complexity: 169 |
Complexity Density: 0.63 |
|
32 |
|
public class TextInput extends InputStream { |
33 |
|
|
34 |
|
|
35 |
|
public static final int EOF = -1; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
public static final char CR = '\012'; |
40 |
|
|
41 |
|
|
42 |
|
private static final String MARKER = "#####"; |
43 |
|
|
44 |
|
|
45 |
|
private final StringBuffer source; |
46 |
|
|
47 |
|
|
48 |
|
private int lineNumber = 0; |
49 |
|
|
50 |
|
|
51 |
|
private int column = 0; |
52 |
|
|
53 |
|
|
54 |
|
private int position = 0; |
55 |
|
|
56 |
|
|
57 |
|
private BigInteger maxIntValue = BigInteger.valueOf(Integer.MAX_VALUE); |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
@param |
63 |
|
@throws |
64 |
|
@throws |
65 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
66 |
2
|
public TextInput(final Reader reader) throws IOException {... |
67 |
2
|
try { |
68 |
2
|
if (reader == null) { |
69 |
1
|
throw new NullPointerException( |
70 |
|
"no null pointer as argument accepted"); |
71 |
|
} |
72 |
1
|
this.source = new StringBuffer(); |
73 |
|
|
74 |
1
|
int c; |
75 |
?
|
while (-1 != (c = reader.read())) { |
76 |
832
|
this.source.append((char) c); |
77 |
|
} |
78 |
|
} finally { |
79 |
2
|
IoUtility.close(reader); |
80 |
|
} |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
@param |
87 |
|
@throws |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
89 |
4
|
public TextInput(final StringBuffer source) {... |
90 |
4
|
if (source == null) { |
91 |
2
|
throw new NullPointerException( |
92 |
|
"no null pointer as argument accepted"); |
93 |
|
} |
94 |
2
|
this.source = source; |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
@param |
101 |
|
@throws |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
103 |
317
|
public TextInput(final String source) {... |
104 |
317
|
if (source == null) { |
105 |
5
|
throw new NullPointerException( |
106 |
|
"no null pointer as argument accepted"); |
107 |
|
} |
108 |
312
|
this.source = new StringBuffer(source); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
@param |
117 |
|
@throws |
118 |
|
@throws |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
120 |
3
|
public TextInput(final File file, final String encoding) throws IOException {... |
121 |
3
|
if (file == null) { |
122 |
1
|
throw new NullPointerException( |
123 |
|
"no null pointer as argument accepted"); |
124 |
|
} |
125 |
2
|
this.source = new StringBuffer(); |
126 |
2
|
IoUtility.loadFile(file, source, encoding); |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
@return |
135 |
|
|
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
137 |
16124
|
public final int read() {... |
138 |
16124
|
if (position >= source.length()) { |
139 |
79
|
return EOF; |
140 |
|
} |
141 |
16045
|
if (getChar() == CR) { |
142 |
449
|
lineNumber++; |
143 |
449
|
column = 0; |
144 |
|
} else { |
145 |
15596
|
column++; |
146 |
|
} |
147 |
16045
|
return source.charAt(position++); |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
@return |
156 |
|
|
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 5 |
Complexity Density: 0.38 |
|
158 |
201
|
public final int readInverse() {... |
159 |
201
|
if (position <= 0) { |
160 |
2
|
return -1; |
161 |
|
} |
162 |
199
|
final char c = source.charAt(--position); |
163 |
199
|
if (c == CR) { |
164 |
7
|
lineNumber--; |
165 |
7
|
int pos = source.lastIndexOf("" + CR, position - 1); |
166 |
7
|
if (pos < 0) { |
167 |
5
|
column = position; |
168 |
|
} else { |
169 |
2
|
column = position - 1 - pos; |
170 |
|
} |
171 |
|
} else { |
172 |
192
|
column--; |
173 |
192
|
if (column < 0) { |
174 |
2
|
throw new IllegalStateException("column less then 0"); |
175 |
|
} |
176 |
|
} |
177 |
197
|
return c; |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
@param |
185 |
|
@return |
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
187 |
362
|
public final String readString(final int number) {... |
188 |
362
|
final StringBuffer result = new StringBuffer(number); |
189 |
753
|
for (int i = 0; i < number; i++) { |
190 |
400
|
final int c = read(); |
191 |
400
|
if (c != -1) { |
192 |
391
|
result.append((char) c); |
193 |
|
} else { |
194 |
9
|
break; |
195 |
|
} |
196 |
|
} |
197 |
362
|
return result.toString(); |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
206 |
6
|
public final void forward(final int number) {... |
207 |
838
|
for (int i = 0; i < number; i++) { |
208 |
833
|
final int c = read(); |
209 |
833
|
if (c == -1) { |
210 |
1
|
break; |
211 |
|
} |
212 |
|
} |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
@param |
220 |
|
@return |
221 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
222 |
2
|
public final boolean forward(final String search) {... |
223 |
2
|
final int pos = source.indexOf(search, position); |
224 |
2
|
if (pos < 0) { |
225 |
1
|
setPosition(getMaximumPosition()); |
226 |
1
|
return false; |
227 |
|
} |
228 |
1
|
setPosition(pos); |
229 |
1
|
return true; |
230 |
|
} |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
@return |
238 |
|
|
239 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
240 |
19735
|
public final int getChar() {... |
241 |
19735
|
if (position >= source.length()) { |
242 |
24
|
return -1; |
243 |
|
} |
244 |
19711
|
return source.charAt(position); |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
@param |
254 |
|
@return |
255 |
|
|
256 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
257 |
346
|
public final int getChar(final int skip) {... |
258 |
346
|
if (position + skip < 0 || position + skip >= source.length()) { |
259 |
40
|
return -1; |
260 |
|
} |
261 |
306
|
return source.charAt(position + skip); |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
@param |
269 |
|
@param |
270 |
|
@return |
271 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 6 |
Complexity Density: 1 |
|
272 |
25
|
public final String getSubstring(final int from, final int to) {... |
273 |
25
|
if (from >= to) { |
274 |
8
|
return ""; |
275 |
|
} |
276 |
17
|
final int l = source.length(); |
277 |
13
|
final int f = (from < 0 ? 0 : (from > l ? l : from)); |
278 |
17
|
final int t = (to < 0 ? 0 : (to > l ? l : to)); |
279 |
17
|
return source.substring(f, t); |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
@return |
286 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
287 |
2
|
public final String asString() {... |
288 |
2
|
return source.toString(); |
289 |
|
} |
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
@param |
297 |
|
@param |
298 |
|
@param |
299 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
300 |
3
|
public final void replace(final int from, final int to, final String replacement) {... |
301 |
3
|
source.replace(from, to, replacement); |
302 |
3
|
if (position > from && position < to) { |
303 |
0
|
setPosition(from + replacement.length()); |
304 |
3
|
} else if (position > from) { |
305 |
2
|
setPosition(position - to + from + replacement.length()); |
306 |
|
} |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
314 |
782
|
public final void skipWhiteSpace() {... |
315 |
902
|
while (!isEmpty() && Character.isWhitespace((char) getChar())) { |
316 |
120
|
read(); |
317 |
|
} |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
325 |
6
|
public final void skipWhiteSpaceInverse() {... |
326 |
26
|
while (getPosition() > 0 && Character.isWhitespace((char) getChar(-1))) { |
327 |
20
|
readInverse(); |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
@throws |
336 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 6 |
Complexity Density: 0.75 |
|
337 |
8
|
public final void skipBackToBeginOfXmlTag() {... |
338 |
8
|
if ('<' == getChar()) { |
339 |
2
|
return; |
340 |
|
} |
341 |
6
|
boolean quoted = false; |
342 |
6
|
do { |
343 |
172
|
if (-1 == readInverse()) { |
344 |
0
|
throw new IllegalArgumentException("begin of xml tag not found"); |
345 |
|
} |
346 |
172
|
if ('\"' == getChar()) { |
347 |
16
|
quoted = !quoted; |
348 |
|
} |
349 |
172
|
} while (quoted || '<' != getChar()); |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
355 |
7
|
public final void skipToEndOfLine() {... |
356 |
7
|
int c = 0; |
357 |
7
|
do { |
358 |
60
|
c = read(); |
359 |
60
|
} while (!isEmpty() && c != CR); |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
@throws |
367 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 7 |
Complexity Density: 0.7 |
|
368 |
6
|
public final void skipForwardToEndOfXmlTag() {... |
369 |
6
|
if ('>' == getChar()) { |
370 |
0
|
return; |
371 |
|
} |
372 |
6
|
boolean quoted = false; |
373 |
317
|
while (!isEmpty() && (quoted || '>' != getChar())) { |
374 |
311
|
int c = read(); |
375 |
311
|
if ('\"' == c) { |
376 |
21
|
quoted = !quoted; |
377 |
|
} |
378 |
|
} |
379 |
6
|
if (isEmpty()) { |
380 |
2
|
throw new IllegalArgumentException("end of xml tag not found"); |
381 |
|
} |
382 |
4
|
read(); |
383 |
|
} |
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
@return |
391 |
|
@throws |
392 |
|
|
393 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 10 |
Complexity Density: 1.43 |
|
394 |
13
|
public final String readNextXmlName() {... |
395 |
13
|
skipWhiteSpace(); |
396 |
13
|
if (isEmpty() || '=' == getChar() || '>' == getChar() || '<' == getChar()) { |
397 |
3
|
throw new IllegalArgumentException( |
398 |
|
"begin of attribute or tag expected"); |
399 |
|
} |
400 |
10
|
StringBuffer buffer = new StringBuffer(); |
401 |
42
|
while (!isEmpty() && '=' != getChar() && '>' != getChar() && '<' != getChar() |
402 |
|
&& !Character.isWhitespace((char) getChar())) { |
403 |
32
|
buffer.append((char) read()); |
404 |
|
} |
405 |
10
|
return buffer.toString(); |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
@return |
415 |
|
@throws |
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
|
|
|
| 93.3% |
Uncovered Elements: 2 (30) |
Complexity: 12 |
Complexity Density: 0.67 |
|
423 |
13
|
public final String readNextAttributeValue() {... |
424 |
13
|
skipWhiteSpace(); |
425 |
13
|
if (isEmpty() || '=' != getChar()) { |
426 |
6
|
throw new IllegalArgumentException( |
427 |
|
"\"=\" expected"); |
428 |
|
} |
429 |
7
|
read(); |
430 |
7
|
skipWhiteSpace(); |
431 |
7
|
if (isEmpty() || '>' == getChar()) { |
432 |
0
|
throw new IllegalArgumentException( |
433 |
|
"attribute value expected"); |
434 |
|
} |
435 |
7
|
StringBuffer buffer = new StringBuffer(); |
436 |
7
|
if ('\"' == getChar()) { |
437 |
5
|
read(); |
438 |
56
|
while (!isEmpty() && '\"' != getChar()) { |
439 |
51
|
buffer.append((char) read()); |
440 |
|
} |
441 |
5
|
if ('\"' != getChar()) { |
442 |
2
|
throw new IllegalArgumentException("\" expected"); |
443 |
|
} |
444 |
3
|
read(); |
445 |
|
} else { |
446 |
10
|
while (!isEmpty() && '>' != getChar() |
447 |
|
&& !Character.isWhitespace((char) getChar())) { |
448 |
8
|
buffer.append((char) read()); |
449 |
|
} |
450 |
|
} |
451 |
5
|
return StringUtility.unescapeXml(buffer.toString()); |
452 |
|
} |
453 |
|
|
454 |
|
|
455 |
|
|
456 |
|
|
457 |
|
@return |
458 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
459 |
9684
|
public final boolean isEmpty() {... |
460 |
9684
|
return position >= source.length(); |
461 |
|
} |
462 |
|
|
463 |
|
|
464 |
|
|
465 |
|
|
466 |
|
@param |
467 |
|
@return |
468 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
469 |
16
|
public final boolean isEmpty(final int skip) {... |
470 |
16
|
return position + skip >= source.length(); |
471 |
|
} |
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
|
476 |
|
|
477 |
|
|
478 |
|
@return |
479 |
|
@throws |
480 |
|
|
481 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 5 |
Complexity Density: 0.62 |
|
482 |
13
|
public final String readLetterDigitString() {... |
483 |
13
|
skipWhiteSpace(); |
484 |
13
|
if (isEmpty() || !Character.isLetterOrDigit((char) getChar())) { |
485 |
4
|
read(); |
486 |
4
|
throw new IllegalArgumentException( |
487 |
|
"letter or digit expected"); |
488 |
|
} |
489 |
9
|
StringBuffer buffer = new StringBuffer(); |
490 |
68
|
while (!isEmpty() && Character.isLetterOrDigit((char) getChar())) { |
491 |
59
|
buffer.append((char) read()); |
492 |
|
} |
493 |
9
|
return buffer.toString(); |
494 |
|
} |
495 |
|
|
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
@return |
502 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
503 |
0
|
public final String readStringTilWhitespace() {... |
504 |
0
|
skipWhiteSpace(); |
505 |
0
|
StringBuffer buffer = new StringBuffer(); |
506 |
0
|
while (!isEmpty() && !Character.isWhitespace((char) getChar())) { |
507 |
0
|
buffer.append((char) read()); |
508 |
|
} |
509 |
0
|
return buffer.toString(); |
510 |
|
} |
511 |
|
|
512 |
|
|
513 |
|
|
514 |
|
|
515 |
|
|
516 |
|
|
517 |
|
@return |
518 |
|
@throws |
519 |
|
|
520 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 6 |
Complexity Density: 0.55 |
|
521 |
533
|
public final int readNonNegativeInt() {... |
522 |
533
|
skipWhiteSpace(); |
523 |
533
|
if (isEmpty() || !Character.isDigit((char) getChar())) { |
524 |
12
|
read(); |
525 |
12
|
throw new IllegalArgumentException( |
526 |
|
"digit expected"); |
527 |
|
} |
528 |
521
|
StringBuffer buffer = new StringBuffer(); |
529 |
1460
|
while (!isEmpty() && Character.isDigit((char) getChar())) { |
530 |
939
|
buffer.append((char) read()); |
531 |
|
} |
532 |
521
|
final BigInteger big = new BigInteger(buffer.toString()); |
533 |
521
|
if (1 == big.compareTo(maxIntValue)) { |
534 |
2
|
throw new IllegalArgumentException("this integer is to large! Maximum possible value is " |
535 |
|
+ maxIntValue); |
536 |
|
} |
537 |
519
|
return big.intValue(); |
538 |
|
} |
539 |
|
|
540 |
|
|
541 |
|
|
542 |
|
|
543 |
|
|
544 |
|
|
545 |
|
|
546 |
|
|
547 |
|
@return |
548 |
|
@throws |
549 |
|
|
|
|
| 92% |
Uncovered Elements: 2 (25) |
Complexity: 10 |
Complexity Density: 0.67 |
|
550 |
12
|
public final String readCounter() {... |
551 |
12
|
skipWhiteSpace(); |
552 |
12
|
if (isEmpty()) { |
553 |
2
|
throw new IllegalArgumentException("integer expected"); |
554 |
|
} |
555 |
10
|
StringBuffer buffer = new StringBuffer(); |
556 |
10
|
if (getChar() == '-') { |
557 |
0
|
buffer.append(read()); |
558 |
|
} |
559 |
10
|
final int begin = getPosition(); |
560 |
10
|
if (!Character.isDigit((char) getChar())) { |
561 |
4
|
throw new IllegalArgumentException("digit expected"); |
562 |
|
} |
563 |
32
|
while (!isEmpty() && Character.isDigit((char) getChar())) { |
564 |
26
|
buffer.append((char) read()); |
565 |
|
} |
566 |
6
|
if (buffer.length() >= 2 && ('0' == buffer.charAt(0) |
567 |
|
|| '-' == buffer.charAt(0) && '0' == buffer.charAt(1))) { |
568 |
2
|
setPosition(begin); |
569 |
2
|
throw new IllegalArgumentException("no leading zeros allowed"); |
570 |
|
} |
571 |
4
|
return buffer.toString(); |
572 |
|
} |
573 |
|
|
574 |
|
|
575 |
|
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
|
581 |
|
@return |
582 |
|
@throws |
583 |
|
|
|
|
| 91.3% |
Uncovered Elements: 2 (23) |
Complexity: 7 |
Complexity Density: 0.47 |
|
584 |
10
|
public final String readQuoted() {... |
585 |
10
|
skipWhiteSpace(); |
586 |
10
|
if (isEmpty() || read() != '\"') { |
587 |
2
|
throw new IllegalArgumentException( |
588 |
|
"\" expected"); |
589 |
|
} |
590 |
8
|
StringBuffer unquoted = new StringBuffer(); |
591 |
8
|
char c; |
592 |
8
|
do { |
593 |
28
|
if (isEmpty()) { |
594 |
0
|
throw new IllegalArgumentException( |
595 |
|
"ending \" expected"); |
596 |
|
} |
597 |
28
|
c = (char) read(); |
598 |
28
|
if (c != '\"') { |
599 |
18
|
unquoted.append(c); |
600 |
|
} else { |
601 |
10
|
if (isEmpty() || getChar() != '\"') { |
602 |
8
|
break; |
603 |
|
} |
604 |
2
|
unquoted.append((char) read()); |
605 |
|
} |
606 |
|
} while (true); |
607 |
8
|
return unquoted.toString(); |
608 |
|
} |
609 |
|
|
610 |
|
|
611 |
|
|
612 |
|
|
613 |
|
@return |
614 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
615 |
2922
|
public final int getRow() {... |
616 |
2922
|
return lineNumber + 1; |
617 |
|
} |
618 |
|
|
619 |
|
|
620 |
|
|
621 |
|
|
622 |
|
@return |
623 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
624 |
64
|
public final int getColumn() {... |
625 |
64
|
return column + 1; |
626 |
|
} |
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
@return |
632 |
|
|
|
|
| 73.3% |
Uncovered Elements: 4 (15) |
Complexity: 6 |
Complexity Density: 0.67 |
|
633 |
4
|
public final String getLine() {... |
634 |
4
|
int min = position - 1; |
635 |
4
|
while (min >= 0 && source.charAt(min) != CR) { |
636 |
0
|
min--; |
637 |
|
} |
638 |
4
|
int max = position; |
639 |
244
|
while (max < source.length() |
640 |
|
&& source.charAt(max) != CR) { |
641 |
240
|
max++; |
642 |
|
} |
643 |
4
|
if (min + 1 >= max) { |
644 |
0
|
return ""; |
645 |
|
} |
646 |
4
|
return source.substring(min + 1, max); |
647 |
|
} |
648 |
|
|
649 |
|
|
650 |
|
|
651 |
|
|
652 |
|
|
653 |
|
@return |
654 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
655 |
82
|
public final int getPosition() {... |
656 |
82
|
return position; |
657 |
|
} |
658 |
|
|
659 |
|
|
660 |
|
|
661 |
|
|
662 |
|
@return |
663 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
664 |
0
|
public final SourcePosition getSourcePosition() {... |
665 |
0
|
return new SourcePosition(getRow(), getColumn()); |
666 |
|
} |
667 |
|
|
668 |
|
|
669 |
|
|
670 |
|
|
671 |
|
|
672 |
|
@return |
673 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
674 |
11
|
public final int getMaximumPosition() {... |
675 |
11
|
return source.length(); |
676 |
|
} |
677 |
|
|
678 |
|
|
679 |
|
|
680 |
|
|
681 |
|
@param |
682 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 6 |
Complexity Density: 0.55 |
|
683 |
42
|
public final void setPosition(final int position) {... |
684 |
42
|
if (position >= source.length()) { |
685 |
14
|
this.position = source.length(); |
686 |
28
|
} else if (this.position != position) { |
687 |
27
|
if (position < this.position) { |
688 |
17
|
this.position = 0; |
689 |
17
|
this.lineNumber = 0; |
690 |
17
|
this.column = 0; |
691 |
1689
|
for (int i = 0; i < position; i++) { |
692 |
1672
|
read(); |
693 |
|
} |
694 |
|
} else { |
695 |
368
|
for (int i = this.position; i < position; i++) { |
696 |
358
|
read(); |
697 |
|
} |
698 |
|
} |
699 |
|
} |
700 |
|
} |
701 |
|
|
702 |
|
|
703 |
|
|
704 |
|
|
705 |
|
@param |
706 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
707 |
0
|
public final void setPosition(final SourcePosition position) {... |
708 |
0
|
setRow(position.getRow()); |
709 |
0
|
setColumn(position.getColumn()); |
710 |
|
} |
711 |
|
|
712 |
|
|
713 |
|
|
714 |
|
|
715 |
|
|
716 |
|
@param |
717 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
718 |
0
|
public final void addPosition(final SourcePosition delta) {... |
719 |
0
|
addRow(delta.getRow() - 1); |
720 |
0
|
addColumn(delta.getColumn() - 1); |
721 |
|
} |
722 |
|
|
723 |
|
|
724 |
|
|
725 |
|
|
726 |
|
@param |
727 |
|
|
|
|
| 61.5% |
Uncovered Elements: 10 (26) |
Complexity: 8 |
Complexity Density: 0.57 |
|
728 |
12
|
public final void setRow(final int row) {... |
729 |
12
|
int r = row; |
730 |
|
|
731 |
12
|
if (r <= 0) { |
732 |
0
|
r = 1; |
733 |
|
} |
734 |
|
|
735 |
12
|
if (getRow() == r) { |
736 |
4
|
return; |
737 |
|
} |
738 |
|
|
739 |
8
|
if (getPosition() >= source.length() && getRow() >= r) { |
740 |
0
|
return; |
741 |
|
} |
742 |
8
|
if (getRow() > r) { |
743 |
|
|
744 |
0
|
this.position = 0; |
745 |
0
|
this.lineNumber = 0; |
746 |
0
|
this.column = 0; |
747 |
|
} |
748 |
2898
|
while (getRow() < r) { |
749 |
2890
|
if (EOF == read()) { |
750 |
0
|
return; |
751 |
|
} |
752 |
|
} |
753 |
|
} |
754 |
|
|
755 |
|
|
756 |
|
@link |
757 |
|
|
758 |
|
@param |
759 |
|
@return |
760 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
761 |
0
|
public final SourcePosition getPosition(final int find) {... |
762 |
0
|
int r = 0; |
763 |
0
|
int c = 0; |
764 |
0
|
int i = 0; |
765 |
0
|
while (i < source.length() && i < find) { |
766 |
0
|
if (CR == source.charAt(i)) { |
767 |
0
|
r++; |
768 |
0
|
c = 0; |
769 |
|
} else { |
770 |
0
|
c++; |
771 |
|
} |
772 |
0
|
i++; |
773 |
|
} |
774 |
0
|
return new SourcePosition(r + 1, c + 1); |
775 |
|
} |
776 |
|
|
777 |
|
|
778 |
|
@link |
779 |
|
|
780 |
|
@param |
781 |
|
@return |
782 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
783 |
0
|
public final int getPosition(final SourcePosition position) {... |
784 |
0
|
int find = 0; |
785 |
0
|
int r = 0; |
786 |
|
|
787 |
0
|
while (++r < position.getRow()) { |
788 |
0
|
find = source.indexOf("" + CR, find); |
789 |
0
|
if (-1 == find) { |
790 |
0
|
break; |
791 |
|
} |
792 |
|
} |
793 |
0
|
if (find < 0) { |
794 |
0
|
find = source.length(); |
795 |
|
} |
796 |
0
|
find += position.getColumn(); |
797 |
0
|
if (find > source.length()) { |
798 |
0
|
find = source.length(); |
799 |
|
} |
800 |
0
|
return find; |
801 |
|
} |
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
|
806 |
|
@param |
807 |
|
@return |
808 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
809 |
0
|
public final String getSourceArea(final SourceArea area) {... |
810 |
0
|
return source.substring(getPosition(area.getStartPosition()), |
811 |
|
getPosition(area.getEndPosition())); |
812 |
|
} |
813 |
|
|
814 |
|
|
815 |
|
|
816 |
|
|
817 |
|
@param |
818 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
819 |
0
|
public final void addRow(final int number) {... |
820 |
0
|
setRow(getRow() + number); |
821 |
|
} |
822 |
|
|
823 |
|
|
824 |
|
|
825 |
|
|
826 |
|
|
827 |
|
|
828 |
|
@param |
829 |
|
|
|
|
| 81.8% |
Uncovered Elements: 4 (22) |
Complexity: 8 |
Complexity Density: 0.67 |
|
830 |
4
|
public final void setColumn(final int column) {... |
831 |
4
|
int c = column; |
832 |
|
|
833 |
4
|
if (c <= 0) { |
834 |
0
|
c = 1; |
835 |
|
} |
836 |
|
|
837 |
4
|
if (getColumn() == c) { |
838 |
0
|
return; |
839 |
|
} |
840 |
4
|
if (getColumn() > c) { |
841 |
2
|
do { |
842 |
34
|
this.position--; |
843 |
34
|
this.column--; |
844 |
34
|
} while (getColumn() > c); |
845 |
2
|
return; |
846 |
|
} |
847 |
18
|
while (getChar() != CR && getChar() != EOF && getColumn() < c) { |
848 |
16
|
read(); |
849 |
|
} |
850 |
|
} |
851 |
|
|
852 |
|
|
853 |
|
|
854 |
|
|
855 |
|
@param |
856 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
857 |
0
|
public final void addColumn(final int number) {... |
858 |
0
|
setColumn(getColumn() + number); |
859 |
|
} |
860 |
|
|
861 |
|
|
862 |
|
|
863 |
|
|
864 |
|
@return |
865 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
866 |
0
|
public final String showLinePosition() {... |
867 |
0
|
final String line = getLine(); |
868 |
0
|
final StringBuffer buffer = new StringBuffer(); |
869 |
0
|
final int col = getColumn() - 1; |
870 |
0
|
if (col > 0) { |
871 |
0
|
if (col < line.length()) { |
872 |
0
|
buffer.append(line.substring(0, col)); |
873 |
|
} else { |
874 |
0
|
buffer.append(line); |
875 |
|
} |
876 |
|
} |
877 |
0
|
buffer.append(MARKER); |
878 |
0
|
if (col < line.length()) { |
879 |
0
|
buffer.append(line.substring(col)); |
880 |
|
} |
881 |
0
|
return buffer.toString(); |
882 |
|
} |
883 |
|
|
884 |
|
|
885 |
|
|
886 |
|
|
887 |
|
|
888 |
|
|
889 |
|
|
890 |
|
|
891 |
|
|
892 |
|
|
893 |
|
|
894 |
|
|
895 |
|
|
896 |
|
|
897 |
|
|
898 |
|
|
899 |
|
|
900 |
|
|
901 |
|
|
902 |
|
|
903 |
|
|
904 |
|
|
905 |
|
|
906 |
|
|
907 |
|
} |