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

22
LINES

< > BotCompany Repo | #1025749 // tok_quicknew - new implementation of quickNew

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

Libraryless. Click here for Pure Java version (3505L/21K).

// new Type var; => Type var = new Type;
// new Type<...> var; => Type var = new Type;
svoid tok_quicknew(LS tok) {
  int i = -1;
  while ((i = jfind(tok, i+1, "new <id>")) >= 0) {
    int j = tok_findEndOfType(tok, i+2);
    if (isIdentifier(get(tok, j)) && eqGetOneOf(tok, j+2, ";", ",")) {
      LS vars = ll(get(tok, j));
      int k = j;
      while (eqGet(tok, k+2, ",") && isIdentifier(get(tok, k+4))) {
        k += 4;
        vars.add(tok.get(k));
      }
      S type = joinSubList(tok, i+2, j-1);
      if (!contains(type, ".")) type = tok.get(i+2);
      clearTokens(tok, i, i+2);
      for iVar over vars:
        tokAppend(tok, j+iVar*4, " = new " + type + "()");
      reTok(tok, i, k+3);
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1025749
Snippet name: tok_quicknew - new implementation of quickNew
Eternal ID of this version: #1025749/14
Text MD5: b12f7f86d056d434621a78af61c00441
Transpilation MD5: d21bce3ea738263b6df3d3bf4e2a2be4
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-03-18 20:51:44
Source code size: 736 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 198 / 341
Version history: 13 change(s)
Referenced in: [show references]