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

47
LINES

< > BotCompany Repo | #1022537 // addAlternateStdFunction

JavaX fragment (include)

1  
// add latest include
2  
static S addAlternateStdFunction(S listID) {
3  
  loading {
4  
    ret addAlternateStdFunction(listID, findLatestInclude().id, true);
5  
  }
6  
}
7  
8  
static S addAlternateStdFunction(S listID, bool realEdit) {
9  
  ret addAlternateStdFunction(listID, findLatestInclude().id, realEdit);
10  
}
11  
12  
static S addAlternateStdFunction(S listID, S snippetID, bool realEdit) {
13  
  snippetID = fsI(snippetID);
14  
  loading {
15  
    LS names = findFunctionDefinitions(loadSnippet(snippetID));
16  
    printStructure("Functions defined in " + snippetID + ": ", names);
17  
    if (empty(names)) ret "No functions found in " + snippetID;
18  
    S name = firstNotStartingWith(names, "_onLoad_");
19  
    if (empty(names)) ret "No definable functions found in " + snippetID;
20  
    
21  
    S text = loadSnippet(listID);
22  
    SS map = tok_findStandardFunctionDefinitions(javaTok(text));
23  
    S def = map.get(name);
24  
    S result = "";
25  
    if (def == null) {
26  
      print(result = "Defining " + name + ".");
27  
      
28  
      S newText = appendWithNewLine(text, "function " + name + " is in " + snippetID + ".");
29  
      print();
30  
      print(unidiff(text, newText));
31  
      if (!realEdit)
32  
        print(result += " Not editing (test mode).");
33  
      else {
34  
        editSnippet(listID, newText);
35  
        triggerTranspilerDirty();
36  
        print(result += " Edited " + listID + ". Now " + countLines(newText) + " lines!");
37  
      }
38  
    } else {
39  
      print(result = "Function " + name + " already defined as " + def);
40  
      if (sameSnippetID(def, snippetID))
41  
        print("Exiting.");
42  
      else
43  
        print("Will not redefine as " + snippetID + ".");
44  
    }
45  
    ret result;
46  
  }
47  
}

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: 295 / 338
Version history: 3 change(s)
Referenced in: [show references]