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).

!636
!standard functions
!L<S>

m {
  p {
    L<S> tok = javaTok(loadMainJava());
    for (L<S> c : allClasses(tok)) {
      print("Double stuff remover: Processing class " + getClassDeclarationName(c));
      new Set<S> vars;
      new Set<S> classes;
      
      for (L<S> ic : innerClasses(c)) {
        S name = getClassDeclarationName(ic);
        print("Found inner class " + name);
        if (classes.contains(name)) {
          print("Removing duplicate inner class " + name);
          clearAllTokens(ic);
          ic.set(ic.size()-1, "\n"); // generous line break :)
        } else
          classes.add(name);
      }
      
      L<S> c2 = javaTok(join(c)); // retokenize
      
      //print(join(c));
      
      try {
        for (L<S> v : allVariableDeclarations(c2)) {
          S name = getVarDeclarationName(v);
          print("Found var " + name);
          if (vars.contains(name)) {
            print("Removing duplicate variable " + name);
            clearAllTokens(v);
            v.set(v.size()-1, "\n"); // generous line break :)
          } else
            vars.add(name);
        }
      } catch (Exception e) {
        printStackTrace(e);
      }
      
      clearAllTokens(c);
      c.set(0, join(c2));
    }
    print("done");
    saveMainJava(join(tok));
  }
}

Author comment

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

download  show line numbers  debug dex   

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

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: 581 / 15107
Referenced in: [show references]

Formerly at http://tinybrain.de/1001045 & http://1001045.tinybrain.de