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

47
LINES

< > BotCompany Repo | #1022537 // addAlternateStdFunction

JavaX fragment (include)

// add latest include
static S addAlternateStdFunction(S listID) {
  loading {
    ret addAlternateStdFunction(listID, findLatestInclude().id, true);
  }
}

static S addAlternateStdFunction(S listID, bool realEdit) {
  ret addAlternateStdFunction(listID, findLatestInclude().id, realEdit);
}

static S addAlternateStdFunction(S listID, S snippetID, bool realEdit) {
  snippetID = fsI(snippetID);
  loading {
    LS names = findFunctionDefinitions(loadSnippet(snippetID));
    printStructure("Functions defined in " + snippetID + ": ", names);
    if (empty(names)) ret "No functions found in " + snippetID;
    S name = firstNotStartingWith(names, "_onLoad_");
    if (empty(names)) ret "No definable functions found in " + snippetID;
    
    S text = loadSnippet(listID);
    SS map = tok_findStandardFunctionDefinitions(javaTok(text));
    S def = map.get(name);
    S result = "";
    if (def == null) {
      print(result = "Defining " + name + ".");
      
      S newText = appendWithNewLine(text, "function " + name + " is in " + snippetID + ".");
      print();
      print(unidiff(text, newText));
      if (!realEdit)
        print(result += " Not editing (test mode).");
      else {
        editSnippet(listID, newText);
        triggerTranspilerDirty();
        print(result += " Edited " + listID + ". Now " + countLines(newText) + " lines!");
      }
    } else {
      print(result = "Function " + name + " already defined as " + def);
      if (sameSnippetID(def, snippetID))
        print("Exiting.");
      else
        print("Will not redefine as " + snippetID + ".");
    }
    ret result;
  }
}

Author comment

Began life as a copy of #1003201

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1022537
Snippet name: addAlternateStdFunction
Eternal ID of this version: #1022537/4
Text MD5: 10f143dc2c35dd707b529b78d13c8785
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-20 13:11:10
Source code size: 1663 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 293 / 335
Version history: 3 change(s)
Referenced in: [show references]