protected int previousTokenOnChannel(int i, int channel) {
		sync(i);
		if (i >= size()) {
			// the EOF token is on every channel
			return size() - 1;
		}

		while (i >= 0) {
			Token token = tokens.get(i);
			if (token.getType() == Token.EOF || token.getChannel() == channel) {
				return i;
			}

			i--;
		}

		return i;
	}
Given a starting index, return the index of the previous token on
channel. Return {@code i} if {@code tokens[i]} is on channel. Return -1
if there are no tokens on channel between {@code i} and 0.

<p>
If {@code i} specifies an index at or after the EOF token, the EOF token
index is returned. This is due to the fact that the EOF token is treated
as though it were on every channel.</p>
runtime/Java/src/org/antlr/v4/runtime/BufferedTokenStream.java