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

49
LINES

< > BotCompany Repo | #1001045 // Double variable/double inner class remover (now standard)

JavaX translator [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (444L/4K/11K).

1  
!636
2  
!standard functions
3  
!L<S>
4  
5  
m {
6  
  p {
7  
    L<S> tok = javaTok(loadMainJava());
8  
    for (L<S> c : allClasses(tok)) {
9  
      print("Double stuff remover: Processing class " + getClassDeclarationName(c));
10  
      new Set<S> vars;
11  
      new Set<S> classes;
12  
      
13  
      for (L<S> ic : innerClasses(c)) {
14  
        S name = getClassDeclarationName(ic);
15  
        print("Found inner class " + name);
16  
        if (classes.contains(name)) {
17  
          print("Removing duplicate inner class " + name);
18  
          clearAllTokens(ic);
19  
          ic.set(ic.size()-1, "\n"); // generous line break :)
20  
        } else
21  
          classes.add(name);
22  
      }
23  
      
24  
      L<S> c2 = javaTok(join(c)); // retokenize
25  
      
26  
      //print(join(c));
27  
      
28  
      try {
29  
        for (L<S> v : allVariableDeclarations(c2)) {
30  
          S name = getVarDeclarationName(v);
31  
          print("Found var " + name);
32  
          if (vars.contains(name)) {
33  
            print("Removing duplicate variable " + name);
34  
            clearAllTokens(v);
35  
            v.set(v.size()-1, "\n"); // generous line break :)
36  
          } else
37  
            vars.add(name);
38  
        }
39  
      } catch (Exception e) {
40  
        printStackTrace(e);
41  
      }
42  
      
43  
      clearAllTokens(c);
44  
      c.set(0, join(c2));
45  
    }
46  
    print("done");
47  
    saveMainJava(join(tok));
48  
  }
49  
}

Author comment

Note: Does not yet scan inner classes for duplicate variables.

download  show line numbers  debug dex  old transpilations   

Travelled to 20 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, dhtvkmknsjym, gwrvuhgaqvyk, ishqpsrjomds, jlatgrcjtklg, jtubtzbbkimh, liwcxgsjrgqn, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001045
Snippet name: Double variable/double inner class remover (now standard)
Eternal ID of this version: #1001045/1
Text MD5: 9dc9d6c5cc8bd04660af6062b9573fa7
Transpilation MD5: 3bb43dc5f44eff091f2db2774e23492d
Author: stefan
Category:
Type: JavaX translator
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-21 03:05:30
Source code size: 1348 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 833 / 15555
Referenced in: [show references]