}
private void reformat(Context context, int indent) {
Document doc = context.document();
TokenHierarchy th = TokenHierarchy.get(doc);
TokenSequence ts = th.tokenSequence();
ts.moveStart();
int newIndent = 0;
boolean nextIndent = false;
TreeMap<Integer, Integer> newIdentMap = new TreeMap<Integer, Integer>(new ReverseOrderInteger());
do {
Token token = ts.token();
if (token != null && token.id().ordinal() != PL_SQLLexer.WHITESPACE) {
if (nextIndent) {
newIndent += indent;
nextIndent = false;
}
if (FORMAT_TOKEN_LIST.contains(token.id().ordinal())) {
nextIndent = true;
}
if (LA(token, ts)) {
newIndent -= indent;
}
if (newIndent < 0) {
newIndent = 0;
}
try {
newIdentMap.put(context.lineStartOffset(ts.offset()), newIndent);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
} while (ts.moveNext());
for (Integer line : newIdentMap.keySet()) {
//System.out.println(line + " : " + newIdentMap.get(line));
setIndent(context, line, newIdentMap.get(line));
}
//System.out.println("--------------------");