MCPcopy Index your code
hub / github.com/antlr/codebuff / getTokensOnPreviousLine

Method getTokensOnPreviousLine

src/org/antlr/codebuff/Trainer.java:740–763  ·  view source on GitHub ↗

Search backwards from tokIndex into 'tokens' stream and get all on-channel tokens on previous line with respect to token at tokIndex. return empty list if none found. First token in returned list is the first token on the line.

(CommonTokenStream tokens, int tokIndex, int curLine)

Source from the content-addressed store, hash-verified

738 * the first token on the line.
739 */
740 public static List<Token> getTokensOnPreviousLine(CommonTokenStream tokens, int tokIndex, int curLine) {
741 // first find previous line by looking for real token on line < tokens.get(i)
742 int prevLine = 0;
743 for (int i = tokIndex-1; i>=0; i--) {
744 Token t = tokens.get(i);
745 if ( t.getChannel()==Token.DEFAULT_CHANNEL && t.getLine()<curLine ) {
746 prevLine = t.getLine();
747 tokIndex = i; // start collecting at this index
748 break;
749 }
750 }
751
752 // Now collect the on-channel real tokens for this line
753 List<Token> online = new ArrayList<>();
754 for (int i = tokIndex; i>=0; i--) {
755 Token t = tokens.get(i);
756 if ( t.getChannel()==Token.DEFAULT_CHANNEL ) {
757 if ( t.getLine()<prevLine ) break; // found last token on that previous line
758 online.add(t);
759 }
760 }
761 Collections.reverse(online);
762 return online;
763 }
764
765 public static String _toString(FeatureMetaData[] FEATURES, InputDocument doc, int[] features) {
766 return _toString(FEATURES, doc, features, true);

Callers 3

getAlignmentCategoryMethod · 0.95
processTokenMethod · 0.80
indentMethod · 0.80

Calls 4

getMethod · 0.65
addMethod · 0.65
getLineMethod · 0.45
reverseMethod · 0.45

Tested by

no test coverage detected