Example usage for org.antlr.v4.runtime IntStream size

List of usage examples for org.antlr.v4.runtime IntStream size

Introduction

In this page you can find the example usage for org.antlr.v4.runtime IntStream size.

Prototype

int size();

Source Link

Document

Returns the total number of symbols in the stream, including a single EOF symbol.

Usage

From source file:com.github.jknack.handlebars.internal.HbsErrorReporter.java

License:Apache License

/**
 * Extract lines./*from   w ww  . j a  v  a2s .co  m*/
 *
 * @param recognizer A lexer/parser.
 * @return Source lines
 */
private String[] lines(final Recognizer<?, ?> recognizer) {
    IntStream stream = recognizer.getInputStream();
    if (stream instanceof CommonTokenStream) {
        stream = ((CommonTokenStream) stream).getTokenSource().getInputStream();
    }
    final String input;
    if (stream instanceof CharStream) {
        input = ((CharStream) stream).getText(new Interval(0, stream.size()));
    } else {
        input = stream.toString();
    }
    String[] lines = input.split("\n");
    return lines;
}