private static void printContext(Object caller, Context<Object> context) { String message = ErrorUtils.printErrorMessage("%s:%s:%s", "", context.getCurrentIndex(), context.getCurrentIndex() + 1, context.getInputBuffer()); System.err.println("*** " + caller + message + "\n\t" + Joiner.on("\n\t - ").join(context.getValueStack())); } }
/** * Prints an error message showing a location in the given InputBuffer. * * @param format the format string, must include three placeholders for a string * (the error message) and two integers (the error line / column respectively) * @param errorMessage the error message * @param errorIndex the error location as an index into the inputBuffer * @param inputBuffer the underlying InputBuffer * @return the error message including the relevant line from the underlying input plus location indicator */ public static String printErrorMessage(String format, String errorMessage, int errorIndex, InputBuffer inputBuffer) { checkArgNotNull(inputBuffer, "inputBuffer"); return printErrorMessage(format, errorMessage, errorIndex, errorIndex + 1, inputBuffer); }
private static void printContext(Object caller, Context<Object> context) { String message = ErrorUtils.printErrorMessage("%s:%s:%s", "", context.getCurrentIndex(), context.getCurrentIndex() + 1, context.getInputBuffer()); System.err.println("*** " + caller + message + "\n\t" + Joiner.on("\n\t - ").join(context.getValueStack())); } }
private static void printContext(Object caller, Context<Object> context) { String message = ErrorUtils.printErrorMessage("%s:%s:%s", "", context.getCurrentIndex(), context.getCurrentIndex() + 1, context.getInputBuffer()); System.err.println("*** " + caller + message + "\n\t" + Joiner.on("\n\t - ").join(context.getValueStack())); } }
/** * Pretty prints the given parse error showing its location in the given input buffer. * * @param error the parse error * @param formatter the formatter for InvalidInputErrors * @return the pretty print text */ public static String printParseError(ParseError error, Formatter<InvalidInputError> formatter) { checkArgNotNull(error, "error"); checkArgNotNull(formatter, "formatter"); String message = error.getErrorMessage() != null ? error.getErrorMessage() : error instanceof InvalidInputError ? formatter.format((InvalidInputError) error) : error.getClass().getSimpleName(); return printErrorMessage("%s (line %s, pos %s):", message, error.getStartIndex(), error.getEndIndex(), error.getInputBuffer()); }