protected void toStringWork(Object p, Object stop, StringBuffer buf) { if (!adaptor.isNil(p)) { String text = adaptor.getText(p); if (text == null) { text = " " + String.valueOf(adaptor.getType(p)); } buf.append(text); // ask the node to go to string } if (p == stop) { return; } int n = adaptor.getChildCount(p); if (n > 0 && !adaptor.isNil(p)) { buf.append(" "); buf.append(Token.DOWN); } for (int c = 0; c < n; c++) { Object child = adaptor.getChild(p, c); toStringWork(child, stop, buf); } if (n > 0 && !adaptor.isNil(p)) { buf.append(" "); buf.append(Token.UP); } }
public int LA(int i) { Object t = LT(i); if (t == null) { return Token.INVALID_TOKEN_TYPE; } return adaptor.getType(t); }
public String toString(Object start, Object stop) { if (start == null) { return null; } // if we have the token stream, use that to dump text in order if (tokens != null) { // don't trust stop node as it's often an UP node etc... // walk backwards until you find a non-UP, non-DOWN node // and ask for it's token index. int beginTokenIndex = adaptor.getTokenStartIndex(start); int endTokenIndex = adaptor.getTokenStopIndex(stop); if (stop != null && adaptor.getType(stop) == Token.UP) { endTokenIndex = adaptor.getTokenStopIndex(start); } else { endTokenIndex = size() - 1; } return tokens.toString(beginTokenIndex, endTokenIndex); } StringBuffer buf = new StringBuffer(); toStringWork(start, stop, buf); return buf.toString(); }