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

47
LINES

< > BotCompany Repo | #1015574 // makeSFSynonym

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

Libraryless. Click here for Pure Java version (13419L/91K).

1  
sS makeSFSynonym(S oldName, S newName) {
2  
  if (eq(oldName, newName))
3  
    fail("Can't make a synonym of itself");
4  
    
5  
  stdFunctions_clearCache();
6  
  S snippetID = stdFunctions_cached().get(oldName);
7  
  if (snippetID == null) {
8  
    snippetID = stdFunctions_cached().get(newName);
9  
    if (snippetID == null)
10  
      fail("Standard function " + oldName + " not found");
11  
    S temp = oldName; oldName = newName; newName = temp;
12  
  }
13  
  
14  
    L<S> tok = javaTok(loadSnippet(snippetID));
15  
  LL<S> funcs = findFullFunctionDefs(tok, true);
16  
  new L<S> out;
17  
  for (L<S> tokF : funcs) {
18  
    int i = indexOfAny(tokF, 0, "(", "{");
19  
    if (i < 0) continue;
20  
    S fname = get(tokF, i-2);
21  
    if (!eq(fname, oldName)) continue;
22  
    L<S> args = tok_parseArgsDeclList(tokF);
23  
    jreplace(tokF = cloneList(tokF), oldName, newName);
24  
    L<S> start = cloneList(subList(tokF, 0, i));
25  
    jreplace(start, "synchronized", "");
26  
    bool isVoid = containsOneOf(start, "void", "svoid");
27  
    out.add(join(start) + "(" + joinWithComma(trimAll(map tok_dropFinal(args))) + ") {\n"
28  
      + "  " + (isVoid ? "" : "ret ") + oldName + "(" + joinWithComma(lmap tok_nameOfParam(args)) + ");\n"
29  
      + "}");
30  
  }
31  
  if (empty(out))
32  
    fail("No functions found");
33  
  print();
34  
  S src = joinWithEmptyLines(out);
35  
  printIndent(src);
36  
37  
  if (isStandardFunction(newName)) {
38  
    S snippetID2 = sfSnippet(newName);
39  
    S result = editSnippet(snippetID2, src);
40  
    ret print("Standard function " + newName + " exists, edited " + snippetID2 + ": " + result);
41  
  }
42  
  
43  
  S newSnippetID = createSnippet(src, newName + " - synonym of " + oldName, snippetType_JavaXInclude());
44  
  checkMarkAnimation_bottomLeft(addStdFunction(newSnippetID, true), 2);
45  
  stdFunctions_clearCache();
46  
  ret "Synonym made!";
47  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1015574
Snippet name: makeSFSynonym
Eternal ID of this version: #1015574/16
Text MD5: 1e7fc60cff02f335f4f8dcb0b46de305
Transpilation MD5: d137761422bd92f9f72dcb1c7a776f0a
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-15 04:17:34
Source code size: 1787 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 416 / 511
Version history: 15 change(s)
Referenced in: [show references]