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

45
LINES

< > BotCompany Repo | #1001159 // allVariableDeclarations

JavaX fragment (include)

1  
// tok = CNC of the class
2  
static L<L<S>> allVariableDeclarations(L<S> tok) {
3  
  new L<L<S>> l;
4  
  int i = 1;
5  
  while (!tok.get(i).equals("{")) i += 2;
6  
  i += 2;
7  
  
8  
  // Now we're inside the class.
9  
  
10  
  while (i < tok.size() && !tok.get(i).equals("}")) {
11  
    //print("i=" + i);
12  
    // parse a declaration (constructor/method/variable/inner class)
13  
    int j = i;
14  
    L<S> special = litlist("=", "{", ";");
15  
    while (j < tok.size() && !special.contains(tok.get(j)))
16  
      j += 2;
17  
      
18  
    if (tok.get(j).equals("{"))
19  
      // method or class declaration - skip
20  
      j = findEndOfBlock(tok, j)+1;
21  
    else {
22  
      // variable declaration
23  
      if (tok.get(j).equals("="))
24  
        j = allVariableDeclarations_findEndOfInitializer(tok, j)+1;
25  
      else
26  
        j += 2; // skip ";"
27  
      l.add(tok.subList(i-1, j));
28  
    }
29  
    
30  
    i = j;
31  
  }
32  
  return l;
33  
}
34  
35  
  // i is a code token pointing at the "="
36  
  // as usual, returns index of last code token + 1
37  
  static int allVariableDeclarations_findEndOfInitializer(L<S> tok, int i) {
38  
    while (i < tok.size() && !tok.get(i).equals(";") && !tok.get(i).equals(",")) {
39  
      if ("{<(".indexOf(tok.get(i)) >= 0)
40  
        i = findEndOfBracketPart(tok, i)+1;
41  
      else
42  
        i += 2;
43  
    }
44  
    return i+1;
45  
  }

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: #1001159
Snippet name: allVariableDeclarations
Eternal ID of this version: #1001159/1
Text MD5: a14412b4e53ff1542b1d57449fc360ae
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-25 17:11:13
Source code size: 1291 bytes / 45 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 550 / 795
Referenced in: [show references]