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.

static new ThreadLocal<Bool> tok_typesAndNamesOfParams_keepModifiers;

static LPairS tok_typesAndNamesOfParams(L<S> tok, O... _) {
  bool keepModifiers = boolPar(tok_typesAndNamesOfParams_keepModifiers);
  optPar bool typelessMeansObject;

  try {
    new L<Pair<S>> out;
    for (int i = 1; i < l(tok); ) {
      i = tok_skipAnnotations(tok, i);
      S t = get(tok, i);
      S pre = "";
      
      ifdef tok_typesAndNamesOfParams_debug
        print("t=" + t + ", next=" + get(tok, i+2));
      endifdef

      // yeah, the typeless handling is a mess...
      if (typelessMeansObject && isIdentifier(t) && eqGetOneOf(tok, i+2, ",", null)) {
        i += 4;
        continue with out.add(pair("Object", t));
      }
      
      if (eqOneOf(t, "final", "transient")) {
        if (keepModifiers) pre += t + " ";
        t = get(tok, i += 2);
      }
      
      if (eq(t, "virtual")) {
        pre += "virtual ";
        t = get(tok, i += 2);
      }
      
      if (eq(t, "new")) { pre += "new "; t = get(tok, i += 2); }
      
      assertTrue(isIdentifier(t));
      i += 2;
      S type = t, name = "?";
      
      while (eq(get(tok, i), ".") && !eqGet(tok, i+2, ".")) {
        type += "." + assertIdentifier(get(tok, i+2));
        i += 4;
      }
      
      // just a parameter name, no type
      if (eqOneOf(get(tok, i), null, ",")) {
        name = type; type = "?";
      } 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 += "[]";
        }
        
        if (eqGet(tok, i, "etc")) {
          i += 2;
          type += " etc";
        }
        
        if (eqGet(tok, i, ".") && eqGet(tok, i+2, ".") && eqGet(tok, i+4, ".")) {
          type += "...";
          i += 6;
        }
        name = assertIdentifier(tok.get(i));
        i += 2;
        while (eq(get(tok, i), "[") && eq(get(tok, i+2), "]")) {
          i += 4;
          type += "[]";
        }
        
        // skip default value
        if (eqGet(tok, i, "default"))
          i = tok_findEndOfExpression(tok, i+2)+1;
          
        if (i < l(tok)) {
          assertEquals(get(tok, i), ",");
          i += 2;
        }
      }
      out.add(pair(pre + type, name));
    }
    ret out;
  } catch e {
    print("Bad parameter declaration: " + sfu(tok));
    throw rethrow(e);
  }
}

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: 509 / 685
Version history: 21 change(s)
Referenced in: [show references]