static LS tok_cleanImports(LS tok) { LS index = toContentsIndexedList(tok); L imports = tok_findImports_returnRanges(tok); new BitSet exclude; for (IntRange r : imports) set(exclude, r.end-4); new L reToks; loop: for (IntRange r : imports) { S id = get(tok, r.end-4); if (!isIdentifier(id)) continue; for (int i : indicesOf(index, id)) if (!get(exclude, i)) continue loop; // id is in use // import is unused - delete clearTokens_addToReToks(tok, r.start+1, r.end, reToks); } reTok_multi(tok, reToks); ret tok; }