/** * Finds the Matcher in the given failedMatcherPath whose label is best for presentation in "expected" strings * of parse error messages, given the provided lastMatchPath. * * @param path the path to the failed matcher * @param errorIndex the start index of the respective parse error * @return the matcher whose label is best for presentation in "expected" strings */ static Matcher findProperLabelMatcher(MatcherPath path, int errorIndex) { try { return findProperLabelMatcher0(path, errorIndex); } catch(RuntimeException e) { if (e == UnderneathTestNot) return null; else throw e; } }
private static Matcher findProperLabelMatcher0(MatcherPath path, int errorIndex) { checkArgNotNull(path, "path"); Matcher found = path.parent != null ? findProperLabelMatcher0(path.parent, errorIndex) : null; if (found != null) return found; Matcher m = path.element.matcher; if (m instanceof TestNotMatcher) throw UnderneathTestNot; if (path.element.startIndex == errorIndex && m.hasCustomLabel()) return m; return null; }