sS indentStructureString(int levels default 100, S s) { if (s == null) null; LS tok = javaTokForStructure(s); new StringBuilder buf; int indent = 0; levels = clampToInt(levels*2L); for i over tok: { S t = tok.get(i); if (isOpeningBracket(t)) { int j = i+5; if (containsClosingBracket(subList(tok, i+2, i+5))) { buf.append(joinSubList(tok, i, j)); i = j-1; } else { indent += 2; buf.append(t); if (indent <= levels) buf.append("\n").append(spaces(indent)); } } else if (isClosingBracket(t)) { indent -= 2; if (indent < levels) buf.append("\n").append(spaces(indent)); buf.append(t); } else if (indent <= levels && eq(t, ",")) { buf.append(t).append("\n").append(spaces(indent)); i++; } else buf.append(t); } ret str(buf); }