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

!752

p {
  L<S> tok = javaTok(loadSnippet("#1002114"));
  Map<Integer, Integer> bracketMap = getBracketMap(tok);
  int i = 0;
  while ((i = findCodeTokens(tok, i+1, "<id>", "=")) >= 0) {
    S name = tok.get(i);
    if (eq(get(tok, i+4), "=")) continue; // it's ==, not =
    int j = scanToEndOfInitializer(tok, bracketMap, i+4);
    print("  " + quote(join(tok.subList(i, j))));
  }
}

static int scanToEndOfInitializer(L<S> tok, Map<Integer, Integer> bracketMap, int i) {
  while (i < l(tok)) {
    if (litlist(";", ",", ")", "}").contains(tok.get(i)))
      ret i-1;
    Integer j = bracketMap.get(i);
    if (j != null)
      i = j+1;
    else
      i++;
  }
  ret i;
}

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