use of org.netbeans.api.lexer.TokenSequence in project enclojure by EricThorsen.
the class ClojureFoldManager method getTopLevelFolds.
public static List<FoldInfo> getTopLevelFolds(BaseDocument doc) {
ArrayList<FoldInfo> foldList = new ArrayList<FoldInfo>();
Stack stack = new Stack();
int start = 0;
int end = 0;
String foldDesc = EMPTY_STRING;
String foldTypeDesc = EMPTY_STRING;
boolean readName = false;
StringBuilder foldText = new StringBuilder();
TokenSequence tokens = TokenHierarchy.get(doc).tokenSequence();
tokens.moveStart();
while (tokens.moveNext()) {
String tk = tokens.token().id().name();
String tkn = tokens.token().toString();
foldText.append(tkn);
if (tk.equals(LIST_START)) {
stack.push(tk);
if (stack.size() == 1)
start = tokens.offset();
} else if (tk.equals(LIST_END)) {
if (!stack.isEmpty())
stack.pop();
if (stack.empty()) {
end = tokens.offset() + 1;
foldList.add(getFoldInfo(start, end, getFoldType(foldTypeDesc), getFoldString(foldText, foldDesc, MAX_FOLD_DESC_LEN)));
start = 0;
end = 0;
foldTypeDesc = EMPTY_STRING;
foldDesc = EMPTY_STRING;
foldText = foldText.replace(0, foldText.length() - 1, EMPTY_STRING);
}
} else if (tkn.equals(DEF) || tkn.equals(DEFN) || tkn.equals(DEFMACRO)) {
foldTypeDesc = tkn;
readName = true;
} else if (readName) {
foldDesc = getFoldDescription(foldTypeDesc, tkn);
readName = false;
}
}
return foldList;
}
Aggregations