Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

21
LINES

< > BotCompany Repo | #1031283 // tok_cleanImports - drop unused imports from Java code

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (3795L) is out of date.

1  
static LS tok_cleanImports(LS tok) {
2  
  LS index = toContentsIndexedList(tok);
3  
  L<IntRange> imports = tok_findImports_returnRanges(tok);
4  
  new BitSet exclude;
5  
  for (IntRange r : imports)
6  
    set(exclude, r.end-4);
7  
    
8  
  new L<IntRange> reToks;
9  
  loop: for (IntRange r : imports) {
10  
    S id = get(tok, r.end-4);
11  
    if (!isIdentifier(id)) continue;
12  
    for (int i : indicesOf(index, id))
13  
      if (!get(exclude, i))
14  
        continue loop; // id is in use
15  
    // import is unused - delete
16  
    clearTokens_addToReToks(tok, r.start+1, r.end, reToks);
17  
  }
18  
  
19  
  reTok_multi(tok, reToks);
20  
  ret tok;
21  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031283
Snippet name: tok_cleanImports - drop unused imports from Java code
Eternal ID of this version: #1031283/11
Text MD5: 491666ffd2e3999e1b4095e866ed2287
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-21 18:24:15
Source code size: 616 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 148 / 224
Version history: 10 change(s)
Referenced in: [show references]