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)
| 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); |
no test coverage detected