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

32
LINES

< > BotCompany Repo | #1030981 // tok_akaFunctionNames [backup before multiple akas]

JavaX fragment (include)

1  
// e.g.
2  
//   void tailCall aka replace(Computable x) {...}
3  
// to:
4  
//   void tailCall(Computable x) {...}
5  
//   void replace(Computable x) { tailCall(x); }
6  
// (or the other way around)
7  
svoid tok_akaFunctionNames(LS tok) {
8  
  int i;
9  
  while ((i = jfind(tok, "<id> aka <id>")) >= 0) {
10  
    int iName1 = i, iName2 = i+4;
11  
    int iOpening = indexOf(tok, i, "(");
12  
    int iClosing = findEndOfBracketPart2(tok, iOpening)-1;
13  
14  
    S name1 = tok.get(iName1), name2 = tok.get(iName2);
15  
    
16  
    int iType = tok_leftScanType(tok, iName1);
17  
    int iStart = tok_leftScanTypeArgsOpt(tok, iType);
18  
    iStart = leftScanModifiers(tok, iStart);
19  
    
20  
    LS _args = subList(tok, iOpening+1, iClosing);
21  
    LS args = tok_parseArgsDeclList2(_args);
22  
    LS type = subList(tok, iType-1, iName1); // return type
23  
    bool isVoid = containsOneOf(codeTokens(type), javaxVoidAliases());
24  
    
25  
    // replace "aka" with params, body and modifiers+return type
26  
    replaceTokens(tok, iName1+1, iName1+4,
27  
      joinSubList(tok, iOpening, iClosing+1)
28  
      + " { " + stringIf(!isVoid, "return ")
29  
      + name2 + "(" + joinWithComma(lmap tok_lastIdentifier(args)) + "); }\n"
30  
      + join(dropFirst(type)));
31  
  }
32  
}

Author comment

Began life as a copy of #1030979

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030981
Snippet name: tok_akaFunctionNames [backup before multiple akas]
Eternal ID of this version: #1030981/3
Text MD5: 49115f22805bae0865644bfbcb4c84c2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-04-18 03:54:18
Source code size: 1203 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 155 / 188
Version history: 2 change(s)
Referenced in: [show references]