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).

sS makeSFSynonym(S oldName, S newName) {
  if (eq(oldName, newName))
    fail("Can't make a synonym of itself");
    
  stdFunctions_clearCache();
  S snippetID = stdFunctions_cached().get(oldName);
  if (snippetID == null) {
    snippetID = stdFunctions_cached().get(newName);
    if (snippetID == null)
      fail("Standard function " + oldName + " not found");
    S temp = oldName; oldName = newName; newName = temp;
  }
  
    L<S> tok = javaTok(loadSnippet(snippetID));
  LL<S> funcs = findFullFunctionDefs(tok, true);
  new L<S> out;
  for (L<S> tokF : funcs) {
    int i = indexOfAny(tokF, 0, "(", "{");
    if (i < 0) continue;
    S fname = get(tokF, i-2);
    if (!eq(fname, oldName)) continue;
    L<S> args = tok_parseArgsDeclList(tokF);
    jreplace(tokF = cloneList(tokF), oldName, newName);
    L<S> start = cloneList(subList(tokF, 0, i));
    jreplace(start, "synchronized", "");
    bool isVoid = containsOneOf(start, "void", "svoid");
    out.add(join(start) + "(" + joinWithComma(trimAll(map tok_dropFinal(args))) + ") {\n"
      + "  " + (isVoid ? "" : "ret ") + oldName + "(" + joinWithComma(lmap tok_nameOfParam(args)) + ");\n"
      + "}");
  }
  if (empty(out))
    fail("No functions found");
  print();
  S src = joinWithEmptyLines(out);
  printIndent(src);

  if (isStandardFunction(newName)) {
    S snippetID2 = sfSnippet(newName);
    S result = editSnippet(snippetID2, src);
    ret print("Standard function " + newName + " exists, edited " + snippetID2 + ": " + result);
  }
  
  S newSnippetID = createSnippet(src, newName + " - synonym of " + oldName, snippetType_JavaXInclude());
  checkMarkAnimation_bottomLeft(addStdFunction(newSnippetID, true), 2);
  stdFunctions_clearCache();
  ret "Synonym made!";
}

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: 418 / 513
Version history: 15 change(s)
Referenced in: [show references]