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

26
LINES

< > BotCompany Repo | #1002117 // Find all initializers

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1412L/10K/31K).

1  
!752
2  
3  
p {
4  
  L<S> tok = javaTok(loadSnippet("#1002114"));
5  
  Map<Integer, Integer> bracketMap = getBracketMap(tok);
6  
  int i = 0;
7  
  while ((i = findCodeTokens(tok, i+1, "<id>", "=")) >= 0) {
8  
    S name = tok.get(i);
9  
    if (eq(get(tok, i+4), "=")) continue; // it's ==, not =
10  
    int j = scanToEndOfInitializer(tok, bracketMap, i+4);
11  
    print("  " + quote(join(tok.subList(i, j))));
12  
  }
13  
}
14  
15  
static int scanToEndOfInitializer(L<S> tok, Map<Integer, Integer> bracketMap, int i) {
16  
  while (i < l(tok)) {
17  
    if (litlist(";", ",", ")", "}").contains(tok.get(i)))
18  
      ret i-1;
19  
    Integer j = bracketMap.get(i);
20  
    if (j != null)
21  
      i = j+1;
22  
    else
23  
      i++;
24  
  }
25  
  ret i;
26  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002117
Snippet name: Find all initializers
Eternal ID of this version: #1002117/1
Text MD5: e1f86588a9c788a861b767f65e30e938
Transpilation MD5: 46f52ad5dfe75e4ba4479f918af12bc9
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-19 02:02:55
Source code size: 699 bytes / 26 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 653 / 726
Referenced in: [show references]