private boolean hasMatchingError(int l, int c) { for (ScriptError e : getErrors()) { if (e.getLineNumber() == l && e.getColumnNumber() == c) { return true; } } return false; }
/** * Returns a concatenation of all errors in contained ScriptError instances. Separated by newline, * except for last error; no \n if only one error. * * @return The Message. * @see ScriptError#getMessage() */ @Override public String getMessage() { StringBuilder sb = new StringBuilder(); if (scriptText == null) { sb.append(super.getMessage()); } else { int l = 1; int c = 0; for (int x = 0; x < scriptText.length(); x++) { if (hasMatchingError(l, c)) { sb.append(" ___ "); } sb.append(scriptText.charAt(x)); if (scriptText.charAt(x) == '\n') { ++l; c = 0; } else { ++c; } } int i = 1; for (ScriptError e : getErrors()) { if (sb.length() > 0) { sb.append('\n'); } sb.append(" "); if (getErrors().size() > 1) { sb.append(i++); sb.append(". "); } sb.append(e.getMessage()); } } return sb.toString(); }
/** * Creates a ScriptException with one Error. * * @param errors */ private ScriptException(final String scriptText, final ScriptError error) { super(error.getMessage()); // ? this.scriptText = scriptText; this.errors = new ArrayList<ScriptError>(1); errors.add(error); }