summaryrefslogtreecommitdiff
path: root/docs/jacoco-ut/bjc.everge/ReplPair.java.html
blob: 9701d2701ae341b432284d679c66ad01b64a6926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>ReplPair.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">everge</a> &gt; <a href="index.source.html" class="el_package">bjc.everge</a> &gt; <span class="el_source">ReplPair.java</span></div><h1>ReplPair.java</h1><pre class="source lang-java linenums">package bjc.everge;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import java.util.function.UnaryOperator;

import bjc.everge.ControlledString.Control;
import bjc.everge.ControlledString.ParseStrings;

/**
 * String pairs for replacements.
 *
 * @author Ben Culkin
 */
public class ReplPair implements Comparable&lt;ReplPair&gt;, UnaryOperator&lt;String&gt; {
	// Line number we read this pair from
	private int lno;

	// Stage this pair is in
	private int stage;

	// Status of this pair with regards to doing staging stuff
<span class="fc" id="L25">	private StageStatus stat = StageStatus.BOTH;</span>

	/**
	 * The priority for this replacement.
	 */
	public int priority;

	/**
	 * The name of this replacement.
	 *
	 * Defaults to the 'find' string.
	 */
	public String name;

	/**
	 * The string to look for.
	 */
	public String find;

	/**
	 * The string to replace it with.
	 */
	public String replace;

	/**
	 * Create a new blank replacement pair.
	 */
	public ReplPair() {
<span class="fc" id="L53">		this(&quot;&quot;, &quot;&quot;, 1, null);</span>
<span class="fc" id="L54">	}</span>

	/**
	 * Create a new replacement pair with a priority of 1.
	 *
	 * @param f
	 * 	The string to find.
	 * @param r
	 * 	The string to replace.
	 */
	public ReplPair(String f, String r) {
<span class="fc" id="L65">		this(f, r, 1);</span>
<span class="fc" id="L66">	}</span>

	/**
	 * Create a new named replacement pair with a priority of 1.
	 *
	 * @param f
	 * 	The string to find.
	 * @param r
	 * 	The string to replace.
	 * @param n
	 * 	The name of the replacement pair.
	 */
	public ReplPair(String f, String r, String n) {
<span class="nc" id="L79">		this(f, r, 1, n);</span>
<span class="nc" id="L80">	}</span>

	/**
	 * Create a new replacement pair with a set priority.
	 *
	 * @param f
	 * 	The string to find.
	 * @param r
	 * 	The string to replace.
	 * @param p
	 * 	The priority for the replacement.
	 */
	public ReplPair(String f, String r, int p) {
<span class="fc" id="L93">		this(f, r, p, f);</span>
<span class="fc" id="L94">	}</span>

	/**
	 * Create a new replacement pair with a set priority and name.
	 *
	 * @param f
	 * 	The string to find.
	 * @param r
	 * 	The string to replace.
	 * @param n
	 * 	The name of the replacement pair.
	 * @param p
	 * 	The priority for the replacement.
	 */
<span class="fc" id="L108">	public ReplPair(String f, String r, int p, String n) {</span>
<span class="fc" id="L109">		find    = f;</span>
<span class="fc" id="L110">		replace = r;</span>

<span class="fc" id="L112">		name = n;</span>

<span class="fc" id="L114">		priority = p;</span>
<span class="fc" id="L115">	}</span>

	/**
	 * Read a list of replacement pairs from an input source.
	 *
	 * @param scn
	 * 	The source to read the replacements from.
	 * @return
	 * 	The list of replacements.
	 */
	public static List&lt;ReplPair&gt; readList(Scanner scn) {
<span class="fc" id="L126">		List&lt;ReplPair&gt; lst = new ArrayList&lt;&gt;();</span>

<span class="fc" id="L128">		return readList(lst, scn);</span>
	}

	/**
	 * Read a list of replacement pairs from an input source, adding them to
	 * an existing list.
	 *
	 * @param detals
	 * 	The list to add the replacements to.
	 * @param scn
	 * 	The source to read the replacements from.
	 * @return
	 * 	The list of replacements.
	 */
	public static List&lt;ReplPair&gt; readList(List&lt;ReplPair&gt; detals, Scanner scn) {
<span class="fc" id="L143">		List&lt;ReplError&gt; errList = new ArrayList&lt;&gt;();</span>

<span class="fc" id="L145">		List&lt;ReplPair&gt; rplPar = readList(detals, scn, errList);</span>

<span class="fc bfc" id="L147" title="All 2 branches covered.">		if (errList.size() != 0) {</span>
<span class="fc" id="L148">			throw new ReplParseException(&quot;&quot;, errList);</span>
		}

<span class="fc" id="L151">		return rplPar;</span>
	}

	/**
	 * Read a list of replacement pairs from an input source, adding them to
	 * an existing list.
	 *
	 * @param detals
	 * 	The list to add the replacements to.
	 * @param scn
	 * 	The source to read the replacements from.
	 * @param errs
	 * 	The list to stick errors in.
	 * @return
	 * 	The list of replacements.
	 */
	public static List&lt;ReplPair&gt; readList(List&lt;ReplPair&gt; detals, Scanner scn, List&lt;ReplError&gt; errs) {
<span class="fc" id="L168">		return readList(detals, scn, errs, new ReplOpts());</span>
	}

	/**
	 * Read a list of replacement pairs from an input source, adding them to
	 * an existing list.
	 *
	 * @param detals
	 * 	The list to add the replacements to.
	 * @param scn
	 * 	The source to read the replacements from.
	 * @param errs
	 * 	The list to stick errors in.
	 * @param ropts
	 * 	The options to use when reading the pairs.
	 * @return
	 * 	The list of replacements.
	 */
	public static List&lt;ReplPair&gt; readList(
			List&lt;ReplPair&gt; detals, Scanner scn,
			List&lt;ReplError&gt; errs, ReplOpts ropts) 
	{
<span class="fc" id="L190">		IntHolder lno = new IntHolder();</span>
<span class="fc" id="L191">		IntHolder pno = new IntHolder();</span>

<span class="fc" id="L193">		List&lt;List&lt;ReplPair&gt;&gt; stages = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L194">		stages.add(new ArrayList&lt;ReplPair&gt;());</span>

		// For every line in the source...
<span class="fc bfc" id="L197" title="All 2 branches covered.">		while (scn.hasNextLine()) {</span>
<span class="fc" id="L198">			String name = scn.nextLine().trim();</span>
<span class="fc" id="L199">			lno.incr();</span>

			// If its commented or blank, skip it
<span class="fc bfc" id="L202" title="All 2 branches covered.">			if (name.equals(&quot;&quot;))      continue;</span>
<span class="fc bfc" id="L203" title="All 2 branches covered.">			if (name.startsWith(&quot;#&quot;)) continue;</span>

			// Global control. Process it.
<span class="fc bfc" id="L206" title="All 2 branches covered.">			if (name.startsWith(&quot;|//&quot;)) {</span>
<span class="fc" id="L207">				readGlobal(name, scn, errs, ropts, lno, pno);</span>

<span class="fc" id="L209">				continue;</span>
			}

<span class="fc" id="L212">			ReplPair rp = new ReplPair();</span>

<span class="fc" id="L214">			rp.priority = ropts.defPrior;</span>
<span class="fc" id="L215">			rp.stat     = ropts.defStatus;</span>
<span class="fc" id="L216">			rp.lno      = lno.get();</span>
<span class="fc" id="L217">			rp.stage    = ropts.defStage;</span>

<span class="fc" id="L219">			boolean isMulti = ropts.defMulti;</span>

			{
<span class="fc" id="L222">				String tmpName = readName(name, scn, errs, rp, ropts, lno, pno);</span>
<span class="pc bpc" id="L223" title="1 of 2 branches missed.">				if (tmpName == null) continue;</span>
<span class="fc" id="L224">				name = tmpName;</span>
			}

<span class="fc" id="L227">			rp.find = name;</span>
<span class="pc bpc" id="L228" title="1 of 2 branches missed.">			if (rp.name == null) rp.name = name;</span>

			// We started to process the pair, mark it as being
			// started
<span class="fc" id="L232">			pno.incr();</span>
<span class="fc" id="L233">			String body = null;</span>

			// Read in the next uncommented line
			do {
<span class="fc bfc" id="L237" title="All 2 branches covered.">				if (!scn.hasNextLine()) break; </span>

<span class="fc" id="L239">				body = scn.nextLine().trim();</span>
<span class="fc" id="L240">				lno.incr();</span>
<span class="pc bpc" id="L241" title="1 of 2 branches missed.">			} while (body.startsWith(&quot;#&quot;));</span>

<span class="fc bfc" id="L243" title="All 2 branches covered.">			if (body == null) {</span>
<span class="fc" id="L244">				String msg = String.format(</span>
						&quot;Ran out of input looking for replacement body for raw name '%s'&quot;, name);

<span class="fc" id="L247">				errs.add(new ReplError(lno, pno, msg, null));</span>
<span class="fc" id="L248">				break;</span>
			}

<span class="fc" id="L251">			isMulti = ropts.defMulti;</span>
			
<span class="fc" id="L253">			ControlledString cs = getControls(body, errs, ropts, lno, pno, &quot;body&quot;);</span>
			// Body has attached controls, process them.
<span class="pc bpc" id="L255" title="1 of 2 branches missed.">			if (cs.hasControls()) {</span>
<span class="nc bnc" id="L256" title="All 2 branches missed.">				for (Control cont : cs.controls) {</span>
<span class="nc bnc" id="L257" title="All 4 branches missed.">					switch (cont.name) {</span>
					case &quot;MULTITRUE&quot;:
					case &quot;MULTIT&quot;:
					case &quot;MT&quot;:
<span class="nc" id="L261">						isMulti = true;</span>
<span class="nc" id="L262">						break;</span>
					case &quot;MULTIFALSE&quot;:
					case &quot;MULTIF&quot;:
					case &quot;MF&quot;:
<span class="nc" id="L266">						isMulti = false;</span>
<span class="nc" id="L267">						break;</span>
					case &quot;MULTI&quot;:
					case &quot;M&quot;:
<span class="nc bnc" id="L270" title="All 2 branches missed.">						if (cont.count() != 1) {</span>
<span class="nc" id="L271">							String errMsg = String.format(&quot;Expected one multi flag (got %d)&quot;, cont.count());</span>
<span class="nc" id="L272">							errs.add(new ReplError(lno, pno, errMsg, body));</span>
<span class="nc" id="L273">						} else {</span>
<span class="nc" id="L274">							isMulti = Boolean.parseBoolean(cont.get(0));</span>
						}
<span class="nc" id="L276">						break;</span>
					default: 
						{
<span class="nc" id="L279">							String errMsg = String.format(&quot;Invalid control name '%s'&quot;, cont.name);</span>
<span class="nc" id="L280">							errs.add(new ReplError(lno, pno, errMsg, body));</span>
						}
						break;
					}
				}

<span class="nc" id="L286">				body = cs.strang;</span>
			}

<span class="fc bfc" id="L289" title="All 2 branches covered.">			if (isMulti) {</span>
<span class="fc" id="L290">				String tmp = readMultiLine(body, scn, ropts, errs, &quot;body&quot;, lno);</span>
<span class="pc bpc" id="L291" title="1 of 2 branches missed.">				if (tmp == null) continue;</span>
<span class="fc" id="L292">				body = tmp;</span>
			}

<span class="fc" id="L295">			rp.replace = body;</span>

<span class="fc" id="L297">			List&lt;ReplPair&gt; stageList = null;</span>
<span class="pc bpc" id="L298" title="1 of 4 branches missed.">			if (rp.stage == 0 || stages.size() &lt; (rp.stage - 1)) {</span>
<span class="fc" id="L299">				stageList = stages.get(rp.stage);</span>

<span class="pc bpc" id="L301" title="1 of 2 branches missed.">				if (stageList == null) {</span>
<span class="nc" id="L302">					stageList = new ArrayList&lt;&gt;();</span>

<span class="nc" id="L304">					stages.add(rp.stage, stageList);</span>
				}
			} else {
<span class="fc bfc" id="L307" title="All 2 branches covered.">				for (int i = stages.size(); i &lt;= rp.stage; i++) {</span>
<span class="fc" id="L308">					stages.add(new ArrayList&lt;&gt;());</span>
				}

<span class="fc" id="L311">				stageList = stages.get(rp.stage);</span>
			}

<span class="pc bpc" id="L314" title="1 of 2 branches missed.">			if (ropts.isTrace) {</span>
<span class="nc" id="L315">				ropts.errStream.printf(&quot;\t[DEBUG] Stage %d: Added %s\n\t\tContents: %s\n&quot;,</span>
<span class="nc" id="L316">						rp.stage, rp, stageList);</span>
			}

<span class="fc" id="L319">			stageList.add(rp);</span>
<span class="fc" id="L320">		}</span>

		// Special-case one-stage processing.
<span class="fc bfc" id="L323" title="All 2 branches covered.">		if (stages.size() == 1) {</span>
<span class="pc bpc" id="L324" title="1 of 2 branches missed.">			if (ropts.isTrace) ropts.errStream.printf(&quot;\t[DEBUG] Executing single-stage bypass\n&quot;);</span>

<span class="fc bfc" id="L326" title="All 2 branches covered.">			for (ReplPair rp : stages.iterator().next()) {</span>
<span class="pc bpc" id="L327" title="1 of 2 branches missed.">				if (rp.stat == StageStatus.INTERNAL) {</span>
<span class="nc bnc" id="L328" title="All 2 branches missed.">					if (ropts.isTrace) ropts.errStream.printf(&quot;\t[DEBUG] Excluding internal RP %s\n&quot;, rp);</span>

					continue;
				}

<span class="fc" id="L333">				detals.add(rp);</span>
<span class="fc" id="L334">			}</span>

<span class="fc" id="L336">			detals.sort(null);</span>

<span class="fc" id="L338">			return detals;</span>
		}

		// Handle stages
<span class="fc" id="L342">		List&lt;ReplPair&gt; tmpList = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L343">		tmpList.addAll(detals);</span>

<span class="pc bpc" id="L345" title="1 of 2 branches missed.">		if (ropts.isTrace) ropts.errStream.printf(&quot;\t[DEBUG] Stages: %s\n&quot;, stages);</span>

<span class="fc" id="L347">		int procStg = 0;</span>
<span class="fc bfc" id="L348" title="All 2 branches covered.">		for (List&lt;ReplPair&gt; stageList : stages) {</span>
<span class="fc" id="L349">			procStg += 1;</span>
<span class="fc" id="L350">			List&lt;ReplPair&gt; curStage = new ArrayList&lt;&gt;();</span>

<span class="pc bpc" id="L352" title="1 of 2 branches missed.">			if (ropts.isTrace) ropts.errStream.printf(&quot;\t[DEBUG] Staging stage %d of %d: %s\n&quot;,</span>
<span class="nc" id="L353">					procStg, stageList.size(), stageList);</span>

<span class="fc bfc" id="L355" title="All 2 branches covered.">			for (ReplPair rp : stageList) {</span>
				// Process through every pair in the previous
				// stages
<span class="fc bfc" id="L358" title="All 2 branches covered.">				for (ReplPair curPar : tmpList) {</span>
<span class="fc" id="L359">					String tmp = rp.replace.replaceAll(curPar.find, curPar.replace);</span>

<span class="pc bpc" id="L361" title="3 of 4 branches missed.">					if (ropts.isTrace &amp;&amp; !rp.replace.equals(tmp)) {</span>
<span class="nc" id="L362">						ropts.errStream.printf(&quot;\t[DEBUG] Staged '%s' -&gt; '%s'\t%s\n&quot;,</span>
							rp.replace, tmp, curPar);
					}

<span class="fc" id="L366">					rp.replace = tmp;</span>
<span class="fc" id="L367">				}</span>

				// If we're external; add straight to the output
<span class="fc bfc" id="L370" title="All 2 branches covered.">				if (rp.stat == StageStatus.EXTERNAL) {</span>
<span class="pc bpc" id="L371" title="1 of 2 branches missed.">					if (ropts.isTrace) {</span>
<span class="nc" id="L372">						ropts.errStream.printf(&quot;\t[DEBUG] Skipped external for staging: %s\n&quot;,</span>
								rp);
					}

<span class="fc" id="L376">					detals.add(rp);</span>
				} else {
<span class="pc bpc" id="L378" title="1 of 2 branches missed.">					if (ropts.isTrace) {</span>
<span class="nc" id="L379">						ropts.errStream.printf(&quot;\t[DEBUG] Added to stage %d: %s\n\t\tContents: %s\n&quot;,</span>
<span class="nc" id="L380">								procStg, rp, curStage);</span>
					}

<span class="fc" id="L383">					curStage.add(rp);</span>
				}
<span class="fc" id="L385">			}</span>
			
<span class="fc" id="L387">			tmpList.addAll(curStage);</span>
<span class="fc" id="L388">			tmpList.sort(null);</span>
<span class="fc" id="L389">		}</span>

		// Copy over to output, excluding internals
<span class="fc bfc" id="L392" title="All 2 branches covered.">		for (ReplPair rp : tmpList) {</span>
<span class="fc bfc" id="L393" title="All 2 branches covered.">			if (rp.stat == StageStatus.INTERNAL) {</span>
<span class="pc bpc" id="L394" title="1 of 2 branches missed.">				if (ropts.isTrace) ropts.errStream.printf(&quot;\t[DEBUG] Excluded internal: %s\n&quot;, rp);</span>

				continue;
			}

<span class="fc" id="L399">			detals.add(rp);</span>
<span class="fc" id="L400">		}</span>

<span class="fc" id="L402">		detals.sort(null);</span>

<span class="pc bpc" id="L404" title="1 of 2 branches missed.">		if (ropts.isTrace) {</span>
<span class="nc" id="L405">			ropts.errStream.printf(&quot;\t[DEBUG] Final output: %s\n&quot;, detals);</span>
		}

<span class="fc" id="L408">		return detals;</span>
	}

	private static String readMultiLine(String lead, Scanner src, ReplOpts ropts,
			List&lt;ReplError&gt; errs, String typ, IntHolder lno) {
<span class="fc" id="L413">		String tmp = lead;</span>

<span class="pc bpc" id="L415" title="3 of 4 branches missed.">		if (ropts.isTrace &amp;&amp; tmp.endsWith(&quot;\\&quot;)) </span>
<span class="nc" id="L416">			ropts.errStream.printf(&quot;\t[TRACE] Starting multi-line parse for %s '%s'\n&quot;, typ, tmp);</span>

<span class="fc" id="L418">		boolean didMulti = tmp.endsWith(&quot;\\&quot;);</span>
<span class="fc bfc" id="L419" title="All 2 branches covered.">		while (tmp.endsWith(&quot;\\&quot;)) {</span>
<span class="fc" id="L420">			boolean incNL = tmp.endsWith(&quot;|\\&quot;);</span>

<span class="pc bpc" id="L422" title="1 of 2 branches missed.">			if (!src.hasNextLine()) break;</span>

<span class="fc" id="L424">			String nxt = src.nextLine().trim();</span>
<span class="fc" id="L425">			lno.incr();</span>

<span class="fc bfc" id="L427" title="All 2 branches covered.">			if (nxt.startsWith(&quot;#&quot;)) continue;</span>

<span class="fc bfc" id="L429" title="All 2 branches covered.">			String nlStr = incNL ? &quot;\n&quot; : &quot;&quot;;</span>

<span class="pc bpc" id="L431" title="1 of 2 branches missed.">			if (tmp.endsWith(&quot;\\&quot;)) {</span>
<span class="fc bfc" id="L432" title="All 2 branches covered.">				if (incNL) {</span>
<span class="fc" id="L433">					tmp = tmp.substring(0, tmp.length() - 2);</span>
				} else {
<span class="fc" id="L435">					tmp = tmp.substring(0, tmp.length() - 1);</span>
				}
			}

<span class="fc" id="L439">			tmp = String.format(&quot;%s%s%s&quot;, tmp, nlStr, nxt);</span>
<span class="fc" id="L440">		}</span>

<span class="pc bpc" id="L442" title="3 of 4 branches missed.">		if (ropts.isTrace &amp;&amp; didMulti)</span>
<span class="nc" id="L443">			ropts.errStream.printf(&quot;\t[TRACE] Finished multi-line parse for %s:\n%s\n.\n&quot;,</span>
					typ, tmp);

<span class="fc" id="L446">		return tmp;</span>
	}

	@Override
	public String apply(String inp) {
<span class="fc" id="L451">		return inp.replaceAll(find, replace);</span>
	}

	@Override
	public String toString() {
<span class="fc" id="L456">		String nameStr = &quot;&quot;;</span>

<span class="pc bpc" id="L458" title="1 of 2 branches missed.">		if (!find.equals(name)) nameStr = String.format(&quot;(%s)&quot;, name);</span>

<span class="fc" id="L460">		return String.format(&quot;%ss/(%s)/(%s)/p(%d)&quot;, nameStr, find, replace, priority);</span>
	}

	@Override
	public int compareTo(ReplPair rp) {
<span class="fc bfc" id="L465" title="All 2 branches covered.">		if (this.priority == rp.priority) return this.lno - rp.lno;</span>

<span class="fc" id="L467">		return rp.priority - this.priority;</span>
	}
	
	@Override
	public int hashCode() {
<span class="nc" id="L472">		final int prime = 31;</span>
<span class="nc" id="L473">		int result = 1;</span>
<span class="nc bnc" id="L474" title="All 2 branches missed.">		result = prime * result + ((find == null) ? 0 : find.hashCode());</span>
<span class="nc bnc" id="L475" title="All 2 branches missed.">		result = prime * result + ((name == null) ? 0 : name.hashCode());</span>
<span class="nc" id="L476">		result = prime * result + priority;</span>
<span class="nc bnc" id="L477" title="All 2 branches missed.">		result = prime * result + ((replace == null) ? 0 : replace.hashCode());</span>
<span class="nc" id="L478">		result = prime * result + stage;</span>
<span class="nc" id="L479">		return result;</span>
	}

	@Override
	public boolean equals(Object obj) {
<span class="pc bpc" id="L484" title="1 of 2 branches missed.">		if (this == obj) return true;</span>
<span class="pc bpc" id="L485" title="1 of 2 branches missed.">		if (obj == null) return false;</span>
<span class="pc bpc" id="L486" title="1 of 2 branches missed.">		if (getClass() != obj.getClass()) return false;</span>
<span class="fc" id="L487">		ReplPair other = (ReplPair) obj;</span>
<span class="pc bpc" id="L488" title="1 of 2 branches missed.">		if (find == null) {</span>
<span class="nc bnc" id="L489" title="All 2 branches missed.">			if (other.find != null) return false;</span>
<span class="pc bpc" id="L490" title="1 of 2 branches missed.">		} else if (!find.equals(other.find)) return false;</span>
<span class="pc bpc" id="L491" title="1 of 2 branches missed.">		if (name == null) {</span>
<span class="nc bnc" id="L492" title="All 2 branches missed.">			if (other.name != null) return false;</span>
<span class="pc bpc" id="L493" title="1 of 2 branches missed.">		} else if (!name.equals(other.name)) return false;</span>
<span class="pc bpc" id="L494" title="1 of 2 branches missed.">		if (priority != other.priority) return false;</span>
<span class="pc bpc" id="L495" title="1 of 2 branches missed.">		if (replace == null) {</span>
<span class="nc bnc" id="L496" title="All 2 branches missed.">			if (other.replace != null) return false;</span>
<span class="pc bpc" id="L497" title="1 of 2 branches missed.">		} else if (!replace.equals(other.replace)) return false;</span>
<span class="pc bpc" id="L498" title="1 of 2 branches missed.">		if (stage != other.stage) return false;</span>
<span class="fc" id="L499">		return true;</span>
	}

	private static String readName(String nam, Scanner scn, List&lt;ReplError&gt; errs,
			ReplPair rp, ReplOpts ropts, IntHolder lno, IntHolder pno) {
<span class="fc" id="L504">		ControlledString cs = getControls(nam, errs, ropts, lno, pno, &quot;name&quot;);</span>

<span class="fc" id="L506">		boolean isMulti = ropts.defMulti;</span>

<span class="fc" id="L508">		String name = cs.strang;</span>

<span class="fc bfc" id="L510" title="All 2 branches covered.">		if (cs.hasControls()) {</span>
<span class="fc bfc" id="L511" title="All 2 branches covered.">			for (Control cont : cs.controls) {</span>
<span class="pc bpc" id="L512" title="6 of 10 branches missed.">				switch (cont.name) {</span>
					case &quot;NAME&quot;:
					case &quot;N&quot;:
<span class="nc bnc" id="L515" title="All 2 branches missed.">						if (cont.count() != 1) {</span>
<span class="nc" id="L516">							String errMsg = String.format(&quot;One name argument was expected (got %d)&quot;,</span>
<span class="nc" id="L517">									cont.count());</span>

<span class="nc" id="L519">							errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L520">						} else {</span>
<span class="nc" id="L521">							rp.name = cont.get(0);</span>
						}
<span class="nc" id="L523">						break;</span>
					case &quot;PRIORITY&quot;:
					case &quot;PRIOR&quot;:
					case &quot;P&quot;:
						try {
<span class="pc bpc" id="L528" title="1 of 2 branches missed.">							if (cont.count() != 1) {</span>
<span class="nc" id="L529">								String errMsg = String.format(&quot;One priority argument was expected (got %d&quot;,</span>
<span class="nc" id="L530">										cont.count());</span>

<span class="nc" id="L532">								errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L533">							} else {</span>
<span class="fc" id="L534">								rp.priority = Integer.parseInt(cont.get(0));</span>
							}
<span class="nc" id="L536">						} catch (NumberFormatException nfex) {</span>
<span class="nc" id="L537">							String errMsg = String.format(&quot;'%s' is not a valid priority (must be an integer)&quot;,</span>
<span class="nc" id="L538">									cont.get(0));</span>

<span class="nc" id="L540">							errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="fc" id="L541">						}</span>
<span class="nc" id="L542">						break;</span>
					case &quot;STAGE&quot;:
					case &quot;S&quot;:
						try {
<span class="pc bpc" id="L546" title="1 of 2 branches missed.">							if (cont.count() != 1) {</span>
<span class="nc" id="L547">								String errMsg = String.format(&quot;One stage argument was expected (got %d&quot;,</span>
<span class="nc" id="L548">										cont.count());</span>

<span class="nc" id="L550">								errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L551">							} else {</span>
<span class="fc" id="L552">								int tmpStage = Integer.parseInt(cont.get(0));</span>
<span class="pc bpc" id="L553" title="1 of 2 branches missed.">								if (tmpStage &lt; 0) {</span>
<span class="nc" id="L554">									String errMsg = String.format(&quot;'%s' is not a valid stage (must be a positive integer)&quot;,</span>
<span class="nc" id="L555">											cont.get(0));</span>
<span class="nc" id="L556">									errs.add(new ReplError(lno, pno, errMsg, nam));</span>

<span class="nc" id="L558">									break;</span>
								}
<span class="fc" id="L560">								rp.stage = tmpStage;</span>
							}
<span class="nc" id="L562">						} catch (NumberFormatException nfex) {</span>
<span class="nc" id="L563">							String errMsg = String.format(&quot;'%s' is not a valid stage (must be a positive integer)&quot;,</span>
<span class="nc" id="L564">									cont.get(0));</span>

<span class="nc" id="L566">							errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="fc" id="L567">						}</span>
<span class="nc" id="L568">						break;</span>
					case &quot;MULTITRUE&quot;:
					case &quot;MULTIT&quot;:
					case &quot;MT&quot;:
<span class="nc" id="L572">						isMulti = true;</span>
<span class="nc" id="L573">						break;</span>
					case &quot;MULTIFALSE&quot;:
					case &quot;MULTIF&quot;:
					case &quot;MF&quot;:
<span class="nc" id="L577">						isMulti = false;</span>
<span class="nc" id="L578">						break;</span>
					case &quot;MULTI&quot;:
					case &quot;M&quot;:
<span class="nc bnc" id="L581" title="All 2 branches missed.">						if (cont.count() != 1) {</span>
<span class="nc" id="L582">							String errMsg = String.format(&quot;One multi-flag argument was expected (got %d&quot;,</span>
<span class="nc" id="L583">									cont.count());</span>

<span class="nc" id="L585">							errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L586">						} else {</span>
<span class="nc" id="L587">							isMulti = Boolean.parseBoolean(cont.get(0));</span>
						}
<span class="nc" id="L589">						break;</span>
					case &quot;INTERNAL&quot;:
					case &quot;INT&quot;:
					case &quot;I&quot;:
<span class="fc" id="L593">						rp.stat = StageStatus.INTERNAL;</span>
<span class="fc" id="L594">						break;</span>
					case &quot;EXTERNAL&quot;:
					case &quot;EXT&quot;:
					case &quot;E&quot;:
<span class="fc" id="L598">						rp.stat = StageStatus.EXTERNAL;</span>
<span class="fc" id="L599">						break;</span>
					case &quot;BOTH&quot;:
					case &quot;B&quot;:
<span class="nc" id="L602">						rp.stat = StageStatus.BOTH;</span>
<span class="nc" id="L603">						break;</span>
					default: 
						{
<span class="nc" id="L606">							String errMsg = String.format(&quot;Unknown control name '%s' for name '%s'&quot;,</span>
									cont.name, nam);

<span class="nc" id="L609">							ReplError erd = new ReplError(lno, pno, errMsg, nam);</span>

<span class="nc" id="L611">							errs.add(erd);</span>
						}
						break;
				}
			}

<span class="fc" id="L617">			name = cs.strang;</span>
		}

		// Multi-line name with a trailer
<span class="fc bfc" id="L621" title="All 2 branches covered.">		if (isMulti) {</span>
<span class="fc" id="L622">			String tmp = readMultiLine(name, scn, ropts, errs, &quot;name&quot;, lno);</span>
<span class="pc bpc" id="L623" title="1 of 2 branches missed.">			if (tmp == null) return null;</span>
<span class="fc" id="L624">			name = tmp;</span>
		}

<span class="fc" id="L627">		return name;</span>
	}

	private static void readGlobal(String nam, Scanner scn, List&lt;ReplError&gt; errs,
			ReplOpts ropts, IntHolder lno, IntHolder pno) {
<span class="fc" id="L632">		ControlledString cs = getControls(nam.substring(1), errs, ropts, lno, pno, &quot;global&quot;);</span>

<span class="fc bfc" id="L634" title="All 2 branches covered.">		for (Control cont : cs.controls) {</span>
<span class="pc bpc" id="L635" title="13 of 18 branches missed.">			switch (cont.name) {</span>
			case &quot;PRIORITY&quot;:
			case &quot;PRIOR&quot;:
			case &quot;P&quot;:
				try {
<span class="pc bpc" id="L640" title="1 of 2 branches missed.">					if (cont.count() != 1) {</span>
<span class="nc" id="L641">						String errMsg = String.format(&quot;Must specify 1 priority (%d specified)&quot;,</span>
<span class="nc" id="L642">								cont.count());</span>

<span class="nc" id="L644">						errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L645">					} else {</span>
<span class="fc" id="L646">						int tmp = Integer.parseInt(cont.get(0));</span>
<span class="fc" id="L647">						ropts.defPrior = tmp;</span>
					}
<span class="nc" id="L649">				} catch (NumberFormatException nfex) {</span>
<span class="nc" id="L650">					String errMsg = String.format(&quot;'%s' is not a valid priority (must be an integer)&quot;,</span>
<span class="nc" id="L651">							cont.get(0));</span>

<span class="nc" id="L653">					errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="fc" id="L654">				}</span>
<span class="nc" id="L655">				break;</span>
			case &quot;STAGE&quot;:
			case &quot;S&quot;:
				try {
<span class="pc bpc" id="L659" title="1 of 2 branches missed.">					if (cont.count() != 1) {</span>
<span class="nc" id="L660">						String errMsg = String.format(&quot;Must specify 1 stage (%d specified)&quot;,</span>
<span class="nc" id="L661">								cont.count());</span>

<span class="nc" id="L663">						errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L664">					} else {</span>
<span class="fc" id="L665">						int tmpStage = Integer.parseInt(cont.get(0));</span>

<span class="pc bpc" id="L667" title="1 of 2 branches missed.">						if (tmpStage &lt; 0) {</span>
<span class="nc" id="L668">							String errMsg = String.format(&quot;'%s' is not a valid stage (must be a positive integer)&quot;,</span>
<span class="nc" id="L669">									cont.get(0));</span>

<span class="nc" id="L671">							errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L672">							break;</span>
						}

<span class="fc" id="L675">						ropts.defStage = tmpStage;</span>
					}
<span class="nc" id="L677">				} catch (NumberFormatException nfex) {</span>
<span class="nc" id="L678">					String errMsg = String.format(&quot;'%s' is not a valid stage (must be a positive integer)&quot;,</span>
<span class="nc" id="L679">							cont.get(0));</span>

<span class="nc" id="L681">					errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="fc" id="L682">				}</span>
<span class="nc" id="L683">				break;</span>
			case &quot;MULTITRUE&quot;:
			case &quot;MULTIT&quot;:
			case &quot;MT&quot;:
<span class="nc" id="L687">				ropts.defMulti = true;</span>
<span class="nc" id="L688">				break;</span>
			case &quot;MULTIFALSE&quot;:
			case &quot;MULTIF&quot;:
			case &quot;MF&quot;:
<span class="nc" id="L692">				ropts.defMulti = false;</span>
<span class="nc" id="L693">				break;</span>
			case &quot;MULTI&quot;:
			case &quot;M&quot;:
<span class="pc bpc" id="L696" title="1 of 2 branches missed.">				if (cont.count() != 1) {</span>
<span class="nc" id="L697">					String errMsg = String.format(&quot;Must specify 1 multi-flag (%d specified)&quot;,</span>
<span class="nc" id="L698">							cont.count());</span>

<span class="nc" id="L700">					errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L701">				} else {</span>
<span class="fc" id="L702">					ropts.defMulti = Boolean.parseBoolean(cont.get(0));</span>
				}
<span class="fc" id="L704">				break;</span>
			case &quot;INTERNAL&quot;:
			case &quot;INT&quot;:
			case &quot;I&quot;:
<span class="nc" id="L708">				ropts.defStatus = StageStatus.INTERNAL;</span>
<span class="nc" id="L709">				break;</span>
			case &quot;EXTERNAL&quot;:
			case &quot;EXT&quot;:
			case &quot;E&quot;:
<span class="nc" id="L713">				ropts.defStatus = StageStatus.EXTERNAL;</span>
<span class="nc" id="L714">				break;</span>
			case &quot;BOTH&quot;:
			case &quot;B&quot;:
<span class="nc" id="L717">				ropts.defStatus = StageStatus.BOTH;</span>
<span class="nc" id="L718">				break;</span>
			case &quot;DEBUGTRUE&quot;:
			case &quot;DEBUGT&quot;:
			case &quot;DT&quot;:
<span class="nc" id="L722">				ropts.isDebug = true;</span>
<span class="nc" id="L723">				break;</span>
			case &quot;DEBUGFALSE&quot;:
			case &quot;DEBUGF&quot;:
			case &quot;DF&quot;:
<span class="fc" id="L727">				ropts.isDebug = false;</span>
<span class="fc" id="L728">				break;</span>
			case &quot;DEBUG&quot;:
			case &quot;D&quot;:
<span class="nc bnc" id="L731" title="All 2 branches missed.">				if (cont.count() != 1) {</span>
<span class="nc" id="L732">					String errMsg = String.format(&quot;Must specify 1 debug flag (%d specified)&quot;,</span>
<span class="nc" id="L733">							cont.count());</span>

<span class="nc" id="L735">					errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L736">				} else {</span>
<span class="nc" id="L737">					ropts.isDebug = Boolean.parseBoolean(cont.get(0));</span>
				}
<span class="nc" id="L739">				break;</span>
			case &quot;TRACETRUE&quot;:
			case &quot;TRACET&quot;:
			case &quot;TT&quot;:
<span class="nc" id="L743">				ropts.isTrace = true;</span>
<span class="nc" id="L744">				break;</span>
			case &quot;TRACEFALSE&quot;:
			case &quot;TRACEF&quot;:
			case &quot;TF&quot;:
<span class="fc" id="L748">				ropts.isTrace = false;</span>
<span class="fc" id="L749">				break;</span>
			case &quot;TRACE&quot;:
			case &quot;T&quot;:
<span class="nc bnc" id="L752" title="All 2 branches missed.">				if (cont.count() != 1) {</span>
<span class="nc" id="L753">					String errMsg = String.format(&quot;Must specify 1 trace flag (%d specified)&quot;,</span>
<span class="nc" id="L754">							cont.count());</span>

<span class="nc" id="L756">					errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L757">				} else {</span>
<span class="nc" id="L758">					ropts.isTrace = Boolean.parseBoolean(cont.get(0));</span>
				}
<span class="nc" id="L760">				break;</span>
			case &quot;PERFTRUE&quot;:
			case &quot;PERFT&quot;:
			case &quot;PRFT&quot;:
<span class="nc" id="L764">				ropts.isPerf = true;</span>
<span class="nc" id="L765">				break;</span>
			case &quot;PERFFALSE&quot;:
			case &quot;PERFF&quot;:
			case &quot;PRFF&quot;:
<span class="nc" id="L769">				ropts.isPerf = false;</span>
<span class="nc" id="L770">				break;</span>
			case &quot;PERF&quot;:
			case &quot;PRF&quot;:
<span class="nc bnc" id="L773" title="All 2 branches missed.">				if (cont.count() != 1) {</span>
<span class="nc" id="L774">					String errMsg = String.format(&quot;Must specify 1 perf. flag (%d specified)&quot;,</span>
<span class="nc" id="L775">							cont.count());</span>

<span class="nc" id="L777">					errs.add(new ReplError(lno, pno, errMsg, nam));</span>
<span class="nc" id="L778">				} else {</span>
<span class="nc" id="L779">					ropts.isPerf = Boolean.parseBoolean(cont.get(0));</span>
				}
<span class="nc" id="L781">				break;</span>
			default: 
				{
<span class="nc" id="L784">					String msg = String.format(&quot;Invalid global control name '%s'&quot;, cont.name);</span>
<span class="nc" id="L785">					ReplError err = new ReplError(lno, pno, msg, nam);</span>
<span class="nc" id="L786">					errs.add(err);</span>
				}
				break;
			}

<span class="pc bpc" id="L791" title="1 of 2 branches missed.">			if (ropts.isTrace) </span>
<span class="nc" id="L792">				ropts.errStream.printf(&quot;\t[TRACE] Processed global control '%s'\n&quot;, cont);</span>
		}

<span class="fc" id="L795">		return;</span>
	}
	
	private static ControlledString getControls(String lne, List&lt;ReplError&gt; errs,
			ReplOpts ropts, IntHolder lno, IntHolder pno, String type) 
	{
		try {
<span class="fc" id="L802">			return ControlledString.parse(lne, new ParseStrings(&quot;//&quot;, &quot;;&quot;, &quot;/&quot;, &quot;|&quot;));</span>
<span class="nc" id="L803">		} catch (IllegalArgumentException iaex) {</span>
<span class="nc" id="L804">			String msg = &quot;Did not find control terminator (//) in %s where it should be&quot;;</span>
<span class="nc" id="L805">			msg = String.format(msg, type);</span>

<span class="nc" id="L807">			ReplError re = new ReplError(lno, pno, msg, lne);</span>
<span class="nc" id="L808">			errs.add(re);</span>

<span class="nc" id="L810">			return null;</span>
		}
	}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.2.201808211720</span></div></body></html>