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

65
LINES

< > BotCompany Repo | #1011790 // tok_typesOfParams - converts ... to []

JavaX fragment (include)

1  
static L<S> tok_typesOfParams(L<S> tok) {
2  
  try {
3  
    new L<S> types;
4  
    for (int i = 1; i < l(tok); ) {
5  
      S t = tok.get(i);
6  
      if (eqOneOf(t, "final")) t = get(tok, i += 2);
7  
      
8  
      assertTrue(isIdentifier(t));
9  
      i += 2;
10  
      S type = t;
11  
      
12  
      if (eq(t, "virtual")) {
13  
        type += " " + tok.get(i);
14  
        i += 2;
15  
      }
16  
      
17  
      while (eq(get(tok, i), ".") && isIdentifier(get(tok, i+2))) {
18  
        type += "." + get(tok, i+2);
19  
        i += 4;
20  
      }
21  
      
22  
      // ...
23  
      if (eqGet(tok, i, ".") && eqGet(tok, i+2, ".") && eqGet(tok, i+2, ".")) {
24  
        type += "[]";
25  
        i += 6;
26  
      }
27  
      
28  
      // just a parameter name, no type
29  
      if (eqOneOf(get(tok, i), null, ","))
30  
        t = null;
31  
      else {
32  
        if (eq(tok.get(i), "<")) {
33  
          int j = findEndOfTypeArgs(tok, i)-1;
34  
          while (eq(get(tok, j), "[") && eq(get(tok, j+2), "]")) j += 4;
35  
          type += trimJoinSubList(tok, i, j+1);
36  
          S id = assertIdentifier(tok.get(j+2));
37  
          i = j+2;
38  
        }
39  
        while (eq(get(tok, i), "[") && eq(get(tok, i+2), "]")) {
40  
          i += 4;
41  
          type += "[]";
42  
        }
43  
        S id = assertIdentifier(tok.get(i));
44  
        i += 2;
45  
        while (eq(get(tok, i), "[") && eq(get(tok, i+2), "]")) {
46  
          i += 4;
47  
          type += "[]";
48  
        }
49  
        if (i < l(tok)) {
50  
          assertEquals(get(tok, i), ",");
51  
          i += 2;
52  
        }
53  
      }
54  
      types.add(type);
55  
    }
56  
    ret types;
57  
  } catch e {
58  
    print("Bad parameter declaration: " + join(tok));
59  
    throw rethrow(e);
60  
  }
61  
}
62  
63  
static L<S> tok_typesOfParams(S s) {
64  
  ret tok_typesOfParams(javaTok(s));
65  
}

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: #1011790
Snippet name: tok_typesOfParams - converts ... to []
Eternal ID of this version: #1011790/16
Text MD5: a956f3eea5826bf1581610b82bfee206
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-16 18:31:58
Source code size: 1715 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 304 / 362
Version history: 15 change(s)
Referenced in: [show references]