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

93
LINES

< > BotCompany Repo | #1012741 // tok_typesAndNamesOfParams

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (11831L) is out of date.

1  
static new ThreadLocal<Bool> tok_typesAndNamesOfParams_keepModifiers;
2  
3  
static LPairS tok_typesAndNamesOfParams(L<S> tok, O... _) {
4  
  bool keepModifiers = boolPar(tok_typesAndNamesOfParams_keepModifiers);
5  
  optPar bool typelessMeansObject;
6  
7  
  try {
8  
    new L<Pair<S>> out;
9  
    for (int i = 1; i < l(tok); ) {
10  
      i = tok_skipAnnotations(tok, i);
11  
      S t = get(tok, i);
12  
      S pre = "";
13  
      
14  
      ifdef tok_typesAndNamesOfParams_debug
15  
        print("t=" + t + ", next=" + get(tok, i+2));
16  
      endifdef
17  
18  
      // yeah, the typeless handling is a mess...
19  
      if (typelessMeansObject && isIdentifier(t) && eqGetOneOf(tok, i+2, ",", null)) {
20  
        i += 4;
21  
        continue with out.add(pair("Object", t));
22  
      }
23  
      
24  
      if (eqOneOf(t, "final", "transient")) {
25  
        if (keepModifiers) pre += t + " ";
26  
        t = get(tok, i += 2);
27  
      }
28  
      
29  
      if (eq(t, "virtual")) {
30  
        pre += "virtual ";
31  
        t = get(tok, i += 2);
32  
      }
33  
      
34  
      if (eq(t, "new")) { pre += "new "; t = get(tok, i += 2); }
35  
      
36  
      assertTrue(isIdentifier(t));
37  
      i += 2;
38  
      S type = t, name = "?";
39  
      
40  
      while (eq(get(tok, i), ".") && !eqGet(tok, i+2, ".")) {
41  
        type += "." + assertIdentifier(get(tok, i+2));
42  
        i += 4;
43  
      }
44  
      
45  
      // just a parameter name, no type
46  
      if (eqOneOf(get(tok, i), null, ",")) {
47  
        name = type; type = "?";
48  
      } else {
49  
        if (eq(tok.get(i), "<")) {
50  
          int j = findEndOfTypeArgs(tok, i)-1;
51  
          while (eq(get(tok, j), "[") && eq(get(tok, j+2), "]")) j += 4;
52  
          type += trimJoinSubList(tok, i, j+1);
53  
          S id = assertIdentifier(tok.get(j+2));
54  
          i = j+2;
55  
        }
56  
        while (eq(get(tok, i), "[") && eq(get(tok, i+2), "]")) {
57  
          i += 4;
58  
          type += "[]";
59  
        }
60  
        
61  
        if (eqGet(tok, i, "etc")) {
62  
          i += 2;
63  
          type += " etc";
64  
        }
65  
        
66  
        if (eqGet(tok, i, ".") && eqGet(tok, i+2, ".") && eqGet(tok, i+4, ".")) {
67  
          type += "...";
68  
          i += 6;
69  
        }
70  
        name = assertIdentifier(tok.get(i));
71  
        i += 2;
72  
        while (eq(get(tok, i), "[") && eq(get(tok, i+2), "]")) {
73  
          i += 4;
74  
          type += "[]";
75  
        }
76  
        
77  
        // skip default value
78  
        if (eqGet(tok, i, "default"))
79  
          i = tok_findEndOfExpression(tok, i+2)+1;
80  
          
81  
        if (i < l(tok)) {
82  
          assertEquals(get(tok, i), ",");
83  
          i += 2;
84  
        }
85  
      }
86  
      out.add(pair(pre + type, name));
87  
    }
88  
    ret out;
89  
  } catch e {
90  
    print("Bad parameter declaration: " + sfu(tok));
91  
    throw rethrow(e);
92  
  }
93  
}

Author comment

Began life as a copy of #1011790

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1012741
Snippet name: tok_typesAndNamesOfParams
Eternal ID of this version: #1012741/22
Text MD5: cd3e5381db3b505f849a3e99560f903f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-20 17:38:22
Source code size: 2709 bytes / 93 lines
Pitched / IR pitched: No / No
Views / Downloads: 521 / 700
Version history: 21 change(s)
Referenced in: [show references]