* startToken and returns the contents of the first whitespace token
* following a newline token, or the empty string if no such pattern
* is found.
*/
public static String findIndent(LinkedListTree node) {
LinkedListToken tok = node.getStartToken();
if (tok == null) {
return findIndent(node.getParent());
}
// the start-token of this AST node is actually whitespace, so
// scan forward until we hit a non-WS token,
while (tok.getType()==AS3Parser.NL || tok.getType()==AS3Parser.WS) {
if (tok.getNext() == null) {
break;
}
tok = tok.getNext();
}
// search backwards though the tokens, looking for the start of
// the line,
for (; tok.getPrev()!=null; tok=tok.getPrev()) {
if (tok.getType() == AS3Parser.NL) {
break;
}
}
if (tok.getType() == AS3Parser.WS) {
return tok.getText();
}
if (tok.getType()!=AS3Parser.NL) {
return "";
}
LinkedListToken startOfLine = tok.getNext();
if (startOfLine.getType() == AS3Parser.WS) {
return startOfLine.getText();
}
return "";
}