!7

p-experiment {
  makeSFSynonym("setTextAndSelectAll", "setTextSelectAll");
}

svoid makeSFSynonym(S oldName, S newName) {
  S snippetID = stdFunctions_cached().get(oldName);
  if (snippetID == null)
    fail("Standard function " + oldName + " not found");
  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(tok, i-2);
    if (!eq(fname, oldName)) continue;
    L<S> args = tok_parseArgsList(tokF);
    jreplace(tokF, oldName, newName);
    L<S> start = subList(tok, 0, i);
    bool isVoid = contains(start, "void");
    out.add(join(start) + "(" + joinWithComma(trimAll(map tok_dropFinal(args))) + ") {\n"
      + "  " + (isVoid ? "" : "ret ") + oldName + "(" + joinWithComma(map tok_lastIdentifier(args)) + ");\n"
      + "}");
  }
  print();
  printIndent(joinWithEmptyLines(out));
}