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

28
LINES

< > BotCompany Repo | #719 // List all inner classes (reflection enhancer)

JavaX translator [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (1690L/11K/26K).

!636
!standard functions
!class JavaTok
!quicknew

main {
  psvm {
    List<String> tok = JavaTok.split(loadMainJava());
    
    // scan for classes, put list in "buf"
    new StringBuilder buf;
    int level = 0;
    for (int i = 1; i+4 < tok.size(); i += 2) {
      if (tok.get(i).equals("{")) ++level;
      else if (tok.get(i).equals("}")) --level;
      else if (level == 1 && tok.get(i).equals("static") && tok.get(i+2).equals("class"))
        buf.append(quote(tok.get(i+4)) + ",\n");
    }
    
    // inject list into source code
    for (int i = 1; i+4 < tok.size(); i += 2)
      if (tok.get(i).equals("]") && tok.get(i+2).equals("innerClasses")
        && tok.get(i+4).equals(";"))
        tok.set(i+4, "={\n" + buf + "};"); // quick&dirty!

    saveMainJava(JavaTok.join(tok));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, mrjhfnjfopze, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
435 #1000610 (pitcher) 2015-08-18 14:38:53
434 #1000604 (pitcher) 2015-08-18 14:38:53

add comment

Snippet ID: #719
Snippet name: List all inner classes (reflection enhancer)
Eternal ID of this version: #719/1
Text MD5: 703137187a9b4f8e103bd36487756a80
Transpilation MD5: 46e2aebd8987e7e3fe8c6bbe827b2600
Author: stefan
Category:
Type: JavaX translator
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-18 14:38:53
Source code size: 824 bytes / 28 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 901 / 1999
Referenced in: [show references]