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

37
LINES

< > BotCompany Repo | #1009921 // allVarNamesWithTypes - find all variable/field declarations in a block/class [dev.]

JavaX fragment (include)

static bool allVarNamesWithTypes_debug;

// TODO: array brackets
static SS allVarNamesWithTypes(L<S> tok) {
  bool debug = allVarNamesWithTypes_debug;
  Map<Int, Int> bracketMap = getBracketMap(tok);
  SS vars = litorderedmap();
  
  int i = 1;
  while (i < l(tok)) {
    while (isJavaModifier(tok.get(i))) i += 2;
    
    ...
  
    for (int i = 3; i < tok.size(); i += 2) {
    S t = tok.get(i);
    if (eqOneOf(t, "=", ";", ",")) {
      S v = tok.get(i-2);
      if (isIdentifier(v))
        varNames.add(v);
      if (eq(t, "=")) {
        i = scanToEndOfInitializer(tok, bracketMap, i)+1;
        assertTrue(odd(i));
      }
    } else if (eq(t, "<")) {
      i = findEndOfTypeArgs(tok, i)+1;
      if (debug)
        print("Skipped type args: " + struct(subList(tok, i)));
    } else if (eq(t, "{"))
      i = findEndOfBlock(tok, i)+1; // skip function/class bodies
  }
  return vars;
}

static SS allVarNamesWithTypes(S text) {
  ret allVarNamesWithTypes(javaTok(text));
}

Author comment

Began life as a copy of #1005504

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1009921
Snippet name: allVarNamesWithTypes - find all variable/field declarations in a block/class [dev.]
Eternal ID of this version: #1009921/3
Text MD5: 7b0ce60958ef76ee39d5a5fce6cae3cb
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-26 04:02:09
Source code size: 1017 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 472 / 472
Version history: 2 change(s)
Referenced in: [show references]