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)

static L<S> tok_typesOfParams(L<S> tok) {
  try {
    new L<S> types;
    for (int i = 1; i < l(tok); ) {
      S t = tok.get(i);
      if (eqOneOf(t, "final")) t = get(tok, i += 2);
      
      assertTrue(isIdentifier(t));
      i += 2;
      S type = t;
      
      if (eq(t, "virtual")) {
        type += " " + tok.get(i);
        i += 2;
      }
      
      while (eq(get(tok, i), ".") && isIdentifier(get(tok, i+2))) {
        type += "." + get(tok, i+2);
        i += 4;
      }
      
      // ...
      if (eqGet(tok, i, ".") && eqGet(tok, i+2, ".") && eqGet(tok, i+2, ".")) {
        type += "[]";
        i += 6;
      }
      
      // just a parameter name, no type
      if (eqOneOf(get(tok, i), null, ","))
        t = null;
      else {
        if (eq(tok.get(i), "<")) {
          int j = findEndOfTypeArgs(tok, i)-1;
          while (eq(get(tok, j), "[") && eq(get(tok, j+2), "]")) j += 4;
          type += trimJoinSubList(tok, i, j+1);
          S id = assertIdentifier(tok.get(j+2));
          i = j+2;
        }
        while (eq(get(tok, i), "[") && eq(get(tok, i+2), "]")) {
          i += 4;
          type += "[]";
        }
        S id = assertIdentifier(tok.get(i));
        i += 2;
        while (eq(get(tok, i), "[") && eq(get(tok, i+2), "]")) {
          i += 4;
          type += "[]";
        }
        if (i < l(tok)) {
          assertEquals(get(tok, i), ",");
          i += 2;
        }
      }
      types.add(type);
    }
    ret types;
  } catch e {
    print("Bad parameter declaration: " + join(tok));
    throw rethrow(e);
  }
}

static L<S> tok_typesOfParams(S s) {
  ret tok_typesOfParams(javaTok(s));
}

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: 297 / 356
Version history: 15 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1012741 - tok_typesAndNamesOfParams