diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-06-25 20:16:13 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-06-25 20:16:13 -0400 |
| commit | e30d3b21a84142963e5f217125d6930589910343 (patch) | |
| tree | 7a9da23758348b8280662ba005b256b4dd989de8 /docs/jacoco-ut/bjc.everge/ReplPair.java.html | |
| parent | 65cdd46dce13ca35d73bdf3ebf75789df5581ac9 (diff) | |
Update site
Diffstat (limited to 'docs/jacoco-ut/bjc.everge/ReplPair.java.html')
| -rw-r--r-- | docs/jacoco-ut/bjc.everge/ReplPair.java.html | 815 |
1 files changed, 815 insertions, 0 deletions
diff --git a/docs/jacoco-ut/bjc.everge/ReplPair.java.html b/docs/jacoco-ut/bjc.everge/ReplPair.java.html new file mode 100644 index 0000000..7cfa2b5 --- /dev/null +++ b/docs/jacoco-ut/bjc.everge/ReplPair.java.html @@ -0,0 +1,815 @@ +<?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> > <a href="index.source.html" class="el_package">bjc.everge</a> > <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; + +/** + * String pairs for replacements. + * + * @author Ben Culkin + */ +public class ReplPair implements Comparable<ReplPair>, UnaryOperator<String> { + // 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="L24"> 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="L52"> this("", "", 1, null);</span> +<span class="fc" id="L53"> }</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="L64"> this(f, r, 1);</span> +<span class="fc" id="L65"> }</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="L78"> this(f, r, 1, n);</span> +<span class="nc" id="L79"> }</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="L92"> this(f, r, p, f);</span> +<span class="fc" id="L93"> }</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="L107"> public ReplPair(String f, String r, int p, String n) {</span> +<span class="fc" id="L108"> find = f;</span> +<span class="fc" id="L109"> replace = r;</span> + +<span class="fc" id="L111"> name = n;</span> + +<span class="fc" id="L113"> priority = p;</span> +<span class="fc" id="L114"> }</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<ReplPair> readList(Scanner scn) { +<span class="fc" id="L125"> List<ReplPair> lst = new ArrayList<>();</span> + +<span class="fc" id="L127"> 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<ReplPair> readList(List<ReplPair> detals, Scanner scn) { +<span class="fc" id="L142"> List<ReplError> errList = new ArrayList<>();</span> + +<span class="fc" id="L144"> List<ReplPair> rplPar = readList(detals, scn, errList);</span> + +<span class="fc bfc" id="L146" title="All 2 branches covered."> if (errList.size() != 0) {</span> +<span class="fc" id="L147"> throw new ReplParseException("", errList);</span> + } + +<span class="fc" id="L150"> 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<ReplPair> readList(List<ReplPair> detals, Scanner scn, List<ReplError> errs) { +<span class="fc" id="L167"> 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<ReplPair> readList(List<ReplPair> detals, Scanner scn, + List<ReplError> errs, ReplOpts ropts) { +<span class="fc" id="L187"> IntHolder lno = new IntHolder();</span> +<span class="fc" id="L188"> IntHolder pno = new IntHolder();</span> + +<span class="fc" id="L190"> List<List<ReplPair>> stages = new ArrayList<>();</span> +<span class="fc" id="L191"> stages.add(new ArrayList<ReplPair>());</span> + + // For every line in the source... +<span class="fc bfc" id="L194" title="All 2 branches covered."> while (scn.hasNextLine()) {</span> +<span class="fc" id="L195"> String name = scn.nextLine().trim();</span> +<span class="fc" id="L196"> lno.incr();</span> + + // If its commented or blank, skip it +<span class="fc bfc" id="L199" title="All 2 branches covered."> if (name.equals("")) continue;</span> +<span class="fc bfc" id="L200" title="All 2 branches covered."> if (name.startsWith("#")) continue;</span> + + // Global control. Process it. +<span class="fc bfc" id="L203" title="All 2 branches covered."> if (name.startsWith("|//")) {</span> +<span class="fc" id="L204"> readGlobal(name, scn, errs, ropts, lno, pno);</span> + +<span class="fc" id="L206"> continue;</span> + } + +<span class="fc" id="L209"> ReplPair rp = new ReplPair();</span> + +<span class="fc" id="L211"> rp.priority = ropts.defPrior;</span> +<span class="fc" id="L212"> rp.stat = ropts.defStatus;</span> +<span class="fc" id="L213"> rp.lno = lno.get();</span> +<span class="fc" id="L214"> rp.stage = ropts.defStage;</span> + +<span class="fc" id="L216"> boolean isMulti = ropts.defMulti;</span> + + { +<span class="fc" id="L219"> String tmpName = readName(name, scn, errs, rp, ropts, lno, pno);</span> +<span class="pc bpc" id="L220" title="1 of 2 branches missed."> if (tmpName == null) continue;</span> +<span class="fc" id="L221"> name = tmpName;</span> + } + +<span class="fc" id="L224"> rp.find = name;</span> +<span class="pc bpc" id="L225" 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="L229"> pno.incr();</span> +<span class="fc" id="L230"> String body = null;</span> + + // Read in the next uncommented line + do { +<span class="fc bfc" id="L234" title="All 2 branches covered."> if (!scn.hasNextLine()) break; </span> + +<span class="fc" id="L236"> body = scn.nextLine().trim();</span> +<span class="fc" id="L237"> lno.incr();</span> +<span class="pc bpc" id="L238" title="1 of 2 branches missed."> } while (body.startsWith("#"));</span> + +<span class="fc bfc" id="L240" title="All 2 branches covered."> if (body == null) {</span> +<span class="fc" id="L241"> String msg = </span> + "Ran out of input looking for replacement body for raw name '" + name + "'"; + +<span class="fc" id="L244"> errs.add(new ReplError(lno, pno, msg, null));</span> +<span class="fc" id="L245"> break;</span> + } + +<span class="fc" id="L248"> isMulti = ropts.defMulti;</span> + + // Body has attached controls, process them. +<span class="pc bpc" id="L251" title="1 of 2 branches missed."> if (body.startsWith("//")) {</span> +<span class="nc" id="L252"> body = body.substring(2);</span> + +<span class="nc" id="L254"> String[] bodyBits = StringUtils.escapeSplit("|", "//", body);</span> +<span class="nc bnc" id="L255" title="All 2 branches missed."> if (bodyBits.length < 2) {</span> +<span class="nc" id="L256"> String msg = "Did not find control terminator (//) in body where it should be";</span> + +<span class="nc" id="L258"> errs.add(new ReplError(lno, pno, msg, body));</span> +<span class="nc" id="L259"> continue;</span> + } + +<span class="nc" id="L262"> String contBody = bodyBits[0];</span> +<span class="nc" id="L263"> String actBody = bodyBits[1];</span> + + // Split out each control +<span class="nc" id="L266"> String[] bits = StringUtils.escapeSplit("|", ";", actBody);</span> + +<span class="nc bnc" id="L268" title="All 2 branches missed."> for (String bit : bits) {</span> +<span class="nc" id="L269"> String bitHead = bit.toUpperCase();</span> +<span class="nc" id="L270"> String bitBody = bit;</span> + +<span class="nc" id="L272"> String[] bots = StringUtils.escapeSplit("|", "/", bit);</span> +<span class="nc bnc" id="L273" title="All 2 branches missed."> if (bots.length > 1) {</span> +<span class="nc" id="L274"> bitHead = bots[0].toUpperCase();</span> +<span class="nc" id="L275"> bitBody = bots[1];</span> + } + +<span class="nc bnc" id="L278" title="All 4 branches missed."> switch (bitHead) {</span> + case "MULTITRUE": + case "MULTIT": + case "MT": +<span class="nc" id="L282"> isMulti = true;</span> +<span class="nc" id="L283"> break;</span> + case "MULTIFALSE": + case "MULTIF": + case "MF": +<span class="nc" id="L287"> isMulti = false;</span> +<span class="nc" id="L288"> break;</span> + case "MULTI": + case "M": +<span class="nc" id="L291"> isMulti = Boolean.parseBoolean(bitBody);</span> +<span class="nc" id="L292"> break;</span> + default: +<span class="nc" id="L294"> errs.add(new ReplError(lno, pno, String.format("Invalid control name '%s'", bitHead), body));</span> + break; + } + } + +<span class="nc" id="L299"> body = actBody;</span> + } + +<span class="fc bfc" id="L302" title="All 2 branches covered."> if (isMulti) {</span> +<span class="fc" id="L303"> String tmp = readMultiLine(body, scn, ropts, errs, "body", lno);</span> +<span class="pc bpc" id="L304" title="1 of 2 branches missed."> if (tmp == null) continue;</span> +<span class="fc" id="L305"> body = tmp;</span> + } + +<span class="fc" id="L308"> rp.replace = body;</span> + +<span class="fc" id="L310"> List<ReplPair> stageList = null;</span> +<span class="pc bpc" id="L311" title="1 of 4 branches missed."> if (rp.stage == 0 || stages.size() < (rp.stage - 1)) {</span> +<span class="fc" id="L312"> stageList = stages.get(rp.stage);</span> + +<span class="pc bpc" id="L314" title="1 of 2 branches missed."> if (stageList == null) {</span> +<span class="nc" id="L315"> stageList = new ArrayList<>();</span> + +<span class="nc" id="L317"> stages.add(rp.stage, stageList);</span> + } + } else { +<span class="fc bfc" id="L320" title="All 2 branches covered."> for (int i = stages.size(); i <= rp.stage; i++) {</span> +<span class="fc" id="L321"> stages.add(new ArrayList<>());</span> + } + +<span class="fc" id="L324"> stageList = stages.get(rp.stage);</span> + } + +<span class="pc bpc" id="L327" title="1 of 2 branches missed."> if (ropts.isTrace) {</span> +<span class="nc" id="L328"> ropts.errStream.printf("\t[DEBUG] Stage %d: Added %s\n\t\tContents: %s\n",</span> +<span class="nc" id="L329"> rp.stage, rp, stageList);</span> + } + +<span class="fc" id="L332"> stageList.add(rp);</span> +<span class="fc" id="L333"> }</span> + + // Special-case one-stage processing. +<span class="fc bfc" id="L336" title="All 2 branches covered."> if (stages.size() == 1) {</span> +<span class="pc bpc" id="L337" title="1 of 2 branches missed."> if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Executing single-stage bypass\n");</span> + +<span class="fc bfc" id="L339" title="All 2 branches covered."> for (ReplPair rp : stages.iterator().next()) {</span> +<span class="pc bpc" id="L340" title="1 of 2 branches missed."> if (rp.stat == StageStatus.INTERNAL) {</span> +<span class="nc bnc" id="L341" title="All 2 branches missed."> if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Excluding internal RP %s\n", rp);</span> + + continue; + } + +<span class="fc" id="L346"> detals.add(rp);</span> +<span class="fc" id="L347"> }</span> + +<span class="fc" id="L349"> detals.sort(null);</span> + +<span class="fc" id="L351"> return detals;</span> + } + + // Handle stages +<span class="fc" id="L355"> List<ReplPair> tmpList = new ArrayList<>();</span> +<span class="fc" id="L356"> tmpList.addAll(detals);</span> + +<span class="pc bpc" id="L358" title="1 of 2 branches missed."> if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Stages: %s\n", stages);</span> + +<span class="fc" id="L360"> int procStg = 0;</span> +<span class="fc bfc" id="L361" title="All 2 branches covered."> for (List<ReplPair> stageList : stages) {</span> +<span class="fc" id="L362"> procStg += 1;</span> +<span class="fc" id="L363"> List<ReplPair> curStage = new ArrayList<>();</span> + +<span class="pc bpc" id="L365" title="1 of 2 branches missed."> if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Staging stage %d of %d: %s\n",</span> +<span class="nc" id="L366"> procStg, stageList.size(), stageList);</span> + +<span class="fc bfc" id="L368" title="All 2 branches covered."> for (ReplPair rp : stageList) {</span> + // Process through every pair in the previous + // stages +<span class="fc bfc" id="L371" title="All 2 branches covered."> for (ReplPair curPar : tmpList) {</span> +<span class="fc" id="L372"> String tmp = rp.replace.replaceAll(curPar.find, curPar.replace);</span> + +<span class="pc bpc" id="L374" title="3 of 4 branches missed."> if (ropts.isTrace && !rp.replace.equals(tmp)) {</span> +<span class="nc" id="L375"> ropts.errStream.printf("\t[DEBUG] Staged '%s' -> '%s'\t%s\n",</span> + rp.replace, tmp, curPar); + } + +<span class="fc" id="L379"> rp.replace = tmp;</span> +<span class="fc" id="L380"> }</span> + + // If we're external; add straight to the output +<span class="fc bfc" id="L383" title="All 2 branches covered."> if (rp.stat == StageStatus.EXTERNAL) {</span> +<span class="pc bpc" id="L384" title="1 of 2 branches missed."> if (ropts.isTrace) {</span> +<span class="nc" id="L385"> ropts.errStream.printf("\t[DEBUG] Skipped external for staging: %s\n",</span> + rp); + } + +<span class="fc" id="L389"> detals.add(rp);</span> + } else { +<span class="pc bpc" id="L391" title="1 of 2 branches missed."> if (ropts.isTrace) {</span> +<span class="nc" id="L392"> ropts.errStream.printf("\t[DEBUG] Added to stage %d: %s\n\t\tContents: %s\n",</span> +<span class="nc" id="L393"> procStg, rp, curStage);</span> + } + +<span class="fc" id="L396"> curStage.add(rp);</span> + } +<span class="fc" id="L398"> }</span> + +<span class="fc" id="L400"> tmpList.addAll(curStage);</span> +<span class="fc" id="L401"> tmpList.sort(null);</span> +<span class="fc" id="L402"> }</span> + + // Copy over to output, excluding internals +<span class="fc bfc" id="L405" title="All 2 branches covered."> for (ReplPair rp : tmpList) {</span> +<span class="fc bfc" id="L406" title="All 2 branches covered."> if (rp.stat == StageStatus.INTERNAL) {</span> +<span class="pc bpc" id="L407" title="1 of 2 branches missed."> if (ropts.isTrace) ropts.errStream.printf("\t[DEBUG] Excluded internal: %s\n", rp);</span> + + continue; + } + +<span class="fc" id="L412"> detals.add(rp);</span> +<span class="fc" id="L413"> }</span> + +<span class="fc" id="L415"> detals.sort(null);</span> + +<span class="pc bpc" id="L417" title="1 of 2 branches missed."> if (ropts.isTrace) {</span> +<span class="nc" id="L418"> ropts.errStream.printf("\t[DEBUG] Final output: %s\n", detals);</span> + } + +<span class="fc" id="L421"> return detals;</span> + } + + private static String readMultiLine(String lead, Scanner src, ReplOpts ropts, + List<ReplError> errs, String typ, IntHolder lno) { +<span class="fc" id="L426"> String tmp = lead;</span> + +<span class="pc bpc" id="L428" title="3 of 4 branches missed."> if (ropts.isTrace && tmp.endsWith("\\")) </span> +<span class="nc" id="L429"> ropts.errStream.printf("\t[TRACE] Starting multi-line parse for %s '%s'\n", typ, tmp);</span> + +<span class="fc" id="L431"> boolean didMulti = tmp.endsWith("\\");</span> +<span class="fc bfc" id="L432" title="All 2 branches covered."> while (tmp.endsWith("\\")) {</span> +<span class="fc" id="L433"> boolean incNL = tmp.endsWith("|\\");</span> + +<span class="pc bpc" id="L435" title="1 of 2 branches missed."> if (!src.hasNextLine()) break;</span> + +<span class="fc" id="L437"> String nxt = src.nextLine().trim();</span> +<span class="fc" id="L438"> lno.incr();</span> + +<span class="fc bfc" id="L440" title="All 2 branches covered."> if (nxt.startsWith("#")) continue;</span> + +<span class="fc bfc" id="L442" title="All 2 branches covered."> String nlStr = incNL ? "\n" : "";</span> + +<span class="pc bpc" id="L444" title="1 of 2 branches missed."> if (tmp.endsWith("\\")) {</span> +<span class="fc bfc" id="L445" title="All 2 branches covered."> if (incNL) {</span> +<span class="fc" id="L446"> tmp = tmp.substring(0, tmp.length() - 2);</span> + } else { +<span class="fc" id="L448"> tmp = tmp.substring(0, tmp.length() - 1);</span> + } + } + +<span class="fc" id="L452"> tmp = String.format("%s%s%s", tmp, nlStr, nxt);</span> +<span class="fc" id="L453"> }</span> + +<span class="pc bpc" id="L455" title="3 of 4 branches missed."> if (ropts.isTrace && didMulti)</span> +<span class="nc" id="L456"> ropts.errStream.printf("\t[TRACE] Finished multi-line parse for %s:\n%s\n.\n",</span> + typ, tmp); + +<span class="fc" id="L459"> return tmp;</span> + } + + @Override + public String apply(String inp) { +<span class="fc" id="L464"> return inp.replaceAll(find, replace);</span> + } + + @Override + public String toString() { +<span class="fc" id="L469"> String nameStr = "";</span> + +<span class="pc bpc" id="L471" title="1 of 2 branches missed."> if (!find.equals(name)) nameStr = String.format("(%s)", name);</span> + +<span class="fc" id="L473"> return String.format("%ss/%s/%s/p(%d)", nameStr, find, replace, priority);</span> + } + + @Override + public int compareTo(ReplPair rp) { +<span class="fc bfc" id="L478" title="All 2 branches covered."> if (this.priority == rp.priority) return this.lno - rp.lno;</span> + +<span class="fc" id="L480"> return rp.priority - this.priority;</span> + } + + @Override + public boolean equals(Object o) { +<span class="pc bpc" id="L485" title="1 of 2 branches missed."> if (o == null) return false;</span> + +<span class="pc bpc" id="L487" title="1 of 2 branches missed."> if (!getClass().equals(o.getClass())) return false;</span> + +<span class="fc" id="L489"> ReplPair ro = (ReplPair)o;</span> + +<span class="pc bpc" id="L491" title="1 of 2 branches missed."> if (!find.equals(ro.find)) return false;</span> + // lno is not a field we consider for equality +<span class="pc bpc" id="L493" title="1 of 2 branches missed."> if (!name.equals(ro.name)) return false;</span> +<span class="pc bpc" id="L494" title="1 of 2 branches missed."> if (priority != ro.priority) return false;</span> +<span class="pc bpc" id="L495" title="1 of 2 branches missed."> if (!replace.equals(ro.name)) return false;</span> + // stat is not a field we consider for equality + +<span class="fc" id="L498"> return true;</span> + } + + private static String readName(String nam, Scanner scn, List<ReplError> errs, + ReplPair rp, ReplOpts ropts, IntHolder lno, IntHolder pno) { +<span class="fc" id="L503"> String name = nam;</span> + +<span class="fc" id="L505"> boolean isMulti = ropts.defMulti;</span> + + // Name has attached controls, process them. +<span class="fc bfc" id="L508" title="All 2 branches covered."> if (name.startsWith("//")) {</span> +<span class="fc" id="L509"> name = name.substring(2);</span> + +<span class="fc" id="L511"> String[] nameBits = StringUtils.escapeSplit("|", "//", name);</span> + +<span class="pc bpc" id="L513" title="1 of 2 branches missed."> if (nameBits.length < 2) {</span> +<span class="nc" id="L514"> String msg = "Did not find control terminator (//) in name where it should be";</span> + +<span class="nc" id="L516"> errs.add(new ReplError(lno, pno, msg, name));</span> +<span class="nc" id="L517"> return null;</span> + } + +<span class="fc" id="L520"> String contName = nameBits[0];</span> +<span class="fc" id="L521"> String actName = nameBits[1];</span> + + // Split out each control +<span class="fc" id="L524"> String[] bits = StringUtils.escapeSplit("|", ";", contName);</span> + +<span class="fc bfc" id="L526" title="All 2 branches covered."> for (String bit : bits) {</span> +<span class="fc" id="L527"> String bitHead = bit.toUpperCase();</span> +<span class="fc" id="L528"> String bitBody = bit;</span> + +<span class="fc" id="L530"> String[] bots = StringUtils.escapeSplit("|", "/", bit);</span> + +<span class="fc bfc" id="L532" title="All 2 branches covered."> if (bots.length > 1) {</span> +<span class="fc" id="L533"> bitHead = bots[0].toUpperCase();</span> +<span class="fc" id="L534"> bitBody = bots[1];</span> + } + +<span class="pc bpc" id="L537" title="6 of 10 branches missed."> switch (bitHead) {</span> + case "NAME": + case "N": +<span class="nc" id="L540"> rp.name = bitBody;</span> +<span class="nc" id="L541"> break;</span> + case "PRIORITY": + case "PRIOR": + case "P": + try { +<span class="fc" id="L546"> rp.priority = Integer.parseInt(bitBody);</span> +<span class="nc" id="L547"> } catch (NumberFormatException nfex) {</span> +<span class="nc" id="L548"> String errMsg = String.format("'%s' is not a valid priority (must be an integer)", bitBody);</span> +<span class="nc" id="L549"> errs.add(new ReplError(lno, pno, errMsg, name));</span> +<span class="fc" id="L550"> }</span> +<span class="nc" id="L551"> break;</span> + case "STAGE": + case "S": + try { +<span class="fc" id="L555"> int tmpStage = Integer.parseInt(bitBody);</span> +<span class="pc bpc" id="L556" title="1 of 2 branches missed."> if (tmpStage < 0) {</span> +<span class="nc" id="L557"> String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)", bitBody);</span> +<span class="nc" id="L558"> errs.add(new ReplError(lno, pno, errMsg, name));</span> + +<span class="nc" id="L560"> break;</span> + } +<span class="fc" id="L562"> rp.stage = tmpStage;</span> +<span class="nc" id="L563"> } catch (NumberFormatException nfex) {</span> +<span class="nc" id="L564"> String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)", bitBody);</span> +<span class="nc" id="L565"> errs.add(new ReplError(lno, pno, errMsg, name));</span> +<span class="fc" id="L566"> }</span> +<span class="nc" id="L567"> break;</span> + case "MULTITRUE": + case "MULTIT": + case "MT": +<span class="nc" id="L571"> isMulti = true;</span> +<span class="nc" id="L572"> break;</span> + case "MULTIFALSE": + case "MULTIF": + case "MF": +<span class="nc" id="L576"> isMulti = false;</span> +<span class="nc" id="L577"> break;</span> + case "MULTI": + case "M": +<span class="nc" id="L580"> isMulti = Boolean.parseBoolean(bitBody);</span> +<span class="nc" id="L581"> break;</span> + case "INTERNAL": + case "INT": + case "I": +<span class="fc" id="L585"> rp.stat = StageStatus.INTERNAL;</span> +<span class="fc" id="L586"> break;</span> + case "EXTERNAL": + case "EXT": + case "E": +<span class="fc" id="L590"> rp.stat = StageStatus.EXTERNAL;</span> +<span class="fc" id="L591"> break;</span> + case "BOTH": + case "B": +<span class="nc" id="L594"> rp.stat = StageStatus.BOTH;</span> +<span class="nc" id="L595"> break;</span> + default: + { +<span class="nc" id="L598"> ReplError erd = new ReplError(lno, pno,</span> +<span class="nc" id="L599"> String.format("Unknown control name '%s' for name '%s'",</span> + bitHead, name), name); + +<span class="nc" id="L602"> errs.add(erd);</span> + } + break; + } + +<span class="fc" id="L607"> name = actName;</span> + } + + // Multi-line name with a trailer +<span class="pc bpc" id="L611" title="1 of 2 branches missed."> if (isMulti) {</span> +<span class="nc" id="L612"> String tmp = readMultiLine(name, scn, ropts, errs, "name", lno);</span> +<span class="nc bnc" id="L613" title="All 2 branches missed."> if (tmp == null) return null;</span> +<span class="nc" id="L614"> name = tmp;</span> + } + } + +<span class="fc" id="L618"> return name;</span> + } + + private static void readGlobal(String nam, Scanner scn, List<ReplError> errs, + ReplOpts ropts, IntHolder lno, IntHolder pno) { +<span class="fc" id="L623"> String name = nam.substring(3);</span> + + // Split out each control +<span class="fc" id="L626"> String[] bits = StringUtils.escapeSplit("|", ";", name);</span> +<span class="pc bpc" id="L627" title="1 of 2 branches missed."> if (ropts.isTrace) {</span> +<span class="nc" id="L628"> ropts.errStream.printf("\t[TRACE] Split control bits are: \n");</span> +<span class="nc bnc" id="L629" title="All 2 branches missed."> for (String bit : bits) {</span> +<span class="nc" id="L630"> ropts.errStream.printf("%s, ", bit);</span> + } +<span class="nc" id="L632"> ropts.errStream.println();</span> + } +<span class="fc bfc" id="L634" title="All 2 branches covered."> for (String bit : bits) {</span> +<span class="fc" id="L635"> String bitHead = bit.toUpperCase();</span> +<span class="fc" id="L636"> String bitBody = bit;</span> + +<span class="fc" id="L638"> String[] bots = StringUtils.escapeSplit("|", "/", bit);</span> +<span class="fc bfc" id="L639" title="All 2 branches covered."> if (bots.length > 1) {</span> +<span class="fc" id="L640"> bitHead = bots[0];</span> +<span class="fc" id="L641"> bitBody = bots[1];</span> + } + +<span class="pc bpc" id="L644" title="13 of 18 branches missed."> switch (bitHead) {</span> + case "PRIORITY": + case "PRIOR": + case "P": + try { +<span class="fc" id="L649"> int tmp = Integer.parseInt(bitBody);</span> +<span class="fc" id="L650"> ropts.defPrior = tmp;</span> +<span class="nc" id="L651"> } catch (NumberFormatException nfex) {</span> +<span class="nc" id="L652"> String errMsg = String.format("'%s' is not a valid priority (must be an integer)",</span> + bitBody); + +<span class="nc" id="L655"> errs.add(new ReplError(lno, pno, errMsg, name));</span> +<span class="fc" id="L656"> }</span> +<span class="nc" id="L657"> break;</span> + case "STAGE": + case "S": + try { +<span class="fc" id="L661"> int tmpStage = Integer.parseInt(bitBody);</span> + +<span class="pc bpc" id="L663" title="1 of 2 branches missed."> if (tmpStage < 0) {</span> +<span class="nc" id="L664"> String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)",</span> + bitBody); + +<span class="nc" id="L667"> errs.add(new ReplError(lno, pno, errMsg, name));</span> +<span class="nc" id="L668"> break;</span> + } +<span class="fc" id="L670"> ropts.defStage = tmpStage;</span> +<span class="nc" id="L671"> } catch (NumberFormatException nfex) {</span> +<span class="nc" id="L672"> String errMsg = String.format("'%s' is not a valid stage (must be a positive integer)",</span> + bitBody); + +<span class="nc" id="L675"> errs.add(new ReplError(lno, pno, errMsg, name));</span> +<span class="fc" id="L676"> }</span> +<span class="nc" id="L677"> break;</span> + case "MULTITRUE": + case "MULTIT": + case "MT": +<span class="nc" id="L681"> ropts.defMulti = true;</span> +<span class="nc" id="L682"> break;</span> + case "MULTIFALSE": + case "MULTIF": + case "MF": +<span class="nc" id="L686"> ropts.defMulti = false;</span> +<span class="nc" id="L687"> break;</span> + case "MULTI": + case "M": +<span class="fc" id="L690"> ropts.defMulti = Boolean.parseBoolean(bitBody);</span> +<span class="fc" id="L691"> break;</span> + case "INTERNAL": + case "INT": + case "I": +<span class="nc" id="L695"> ropts.defStatus = StageStatus.INTERNAL;</span> +<span class="nc" id="L696"> break;</span> + case "EXTERNAL": + case "EXT": + case "E": +<span class="nc" id="L700"> ropts.defStatus = StageStatus.EXTERNAL;</span> +<span class="nc" id="L701"> break;</span> + case "BOTH": + case "B": +<span class="nc" id="L704"> ropts.defStatus = StageStatus.BOTH;</span> +<span class="nc" id="L705"> break;</span> + case "DEBUGTRUE": + case "DEBUGT": + case "DT": +<span class="nc" id="L709"> ropts.isDebug = true;</span> +<span class="nc" id="L710"> break;</span> + case "DEBUGFALSE": + case "DEBUGF": + case "DF": +<span class="fc" id="L714"> ropts.isDebug = false;</span> +<span class="fc" id="L715"> break;</span> + case "DEBUG": + case "D": +<span class="nc" id="L718"> ropts.isDebug = Boolean.parseBoolean(bitBody);</span> +<span class="nc" id="L719"> break;</span> + case "TRACETRUE": + case "TRACET": + case "TT": +<span class="nc" id="L723"> ropts.isTrace = true;</span> +<span class="nc" id="L724"> break;</span> + case "TRACEFALSE": + case "TRACEF": + case "TF": +<span class="fc" id="L728"> ropts.isTrace = false;</span> +<span class="fc" id="L729"> break;</span> + case "TRACE": + case "T": +<span class="nc" id="L732"> ropts.isTrace = Boolean.parseBoolean(bitBody);</span> +<span class="nc" id="L733"> break;</span> + case "PERFTRUE": + case "PERFT": + case "PRFT": +<span class="nc" id="L737"> ropts.isPerf = true;</span> +<span class="nc" id="L738"> break;</span> + case "PERFFALSE": + case "PERFF": + case "PRFF": +<span class="nc" id="L742"> ropts.isPerf = false;</span> +<span class="nc" id="L743"> break;</span> + case "PERF": + case "PRF": +<span class="nc" id="L746"> ropts.isPerf = Boolean.parseBoolean(bitBody);</span> +<span class="nc" id="L747"> break;</span> + default: + { +<span class="nc" id="L750"> String msg = String.format("Invalid global control name '%s'", bitHead);</span> +<span class="nc" id="L751"> ReplError err = new ReplError(lno, pno, msg, name);</span> +<span class="nc" id="L752"> errs.add(err);</span> + } + break; + } + +<span class="pc bpc" id="L757" title="1 of 2 branches missed."> if (ropts.isTrace) </span> +<span class="nc" id="L758"> ropts.errStream.printf("\t[TRACE] Processed global control '%s':'%s'\n", </span> + bitHead, bitBody); + } + +<span class="fc" id="L762"> return;</span> + } + + private static ControlledString getControls(String lne, List<ReplError> errs, + ReplOpts ropts, IntHolder lno, IntHolder pno, String type) { +<span class="nc bnc" id="L767" title="All 2 branches missed."> if (!lne.startsWith("//")) {</span> +<span class="nc" id="L768"> return new ControlledString(lne);</span> + } + +<span class="nc" id="L771"> String tmp = lne.substring(2);</span> + +<span class="nc" id="L773"> String[] bits = StringUtils.escapeSplit("|", "//", lne);</span> + +<span class="nc bnc" id="L775" title="All 2 branches missed."> if (bits.length < 2) {</span> +<span class="nc" id="L776"> String msg = "Did not find control terminator (//) in %s where it should be";</span> +<span class="nc" id="L777"> msg = String.format(msg, type);</span> + +<span class="nc" id="L779"> ReplError re = new ReplError(lno, pno, msg, lne);</span> +<span class="nc" id="L780"> errs.add(re);</span> + +<span class="nc" id="L782"> return null;</span> + } + +<span class="nc" id="L785"> ControlledString cs = new ControlledString(bits[0]);</span> + +<span class="nc" id="L787"> bits = StringUtils.escapeSplit("|", ";", bits[1]);</span> + +<span class="nc" id="L789"> cs.controls = new Control[bits.length];</span> + +<span class="nc bnc" id="L791" title="All 2 branches missed."> for (int i = 0; i < bits.length; i++) {</span> +<span class="nc" id="L792"> String bit = bits[i];</span> + +<span class="nc" id="L794"> String[] bots = StringUtils.escapeSplit("|", "/", bit);</span> + +<span class="nc" id="L796"> Control cont = new Control(bots[0]);</span> + +<span class="nc bnc" id="L798" title="All 2 branches missed."> if (cont.name.length() > 1) {</span> +<span class="nc" id="L799"> cont.name = cont.name.toUpperCase();</span> + } + +<span class="nc bnc" id="L802" title="All 2 branches missed."> if (bots.length > 1) {</span> +<span class="nc" id="L803"> cont.args = new String[bots.length - 1];</span> +<span class="nc bnc" id="L804" title="All 2 branches missed."> for (int j = 1; j < bots.length; j++) {</span> +<span class="nc" id="L805"> cont.args[j - 1] = bots[j];</span> + } + } + +<span class="nc" id="L809"> cs.controls[i] = cont;</span> + } + +<span class="nc" id="L812"> return cs;</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>
\ No newline at end of file |
