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

48
LINES

< > BotCompany Repo | #1015881 // addStdClass - Add a standard class to list (edits #1003674)

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

Libraryless. Click here for Pure Java version (13010L/87K).

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

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

static S addStdClass(S snippetID, bool realEdit) {
  loading {
    snippetID = fsI(snippetID);
    LS tok = javaTokSnippet(snippetID);
    L<S> names = map getClassDeclarationName(allClasses(tok));
    addAll(names, keys(tok_findRewrites(tok)));
    printStructure("Classes defined in " + snippetID + ": ", names);
    if (empty(names)) ret "No classes found in " + snippetID;
    S name = first(names);
    
    S text = loadSnippet(#1003674);
    SS map = standardClassesMap_uncached();
    S def = map.get(name);
    S result = "";
    if (def == null) {
      print(result = "Defining " + name + ".");
      
      S newText = addToStdClassesList(text, name, snippetID);
      print();
      print(unidiff(text, newText));
      if (!realEdit)
        print(result += " Not editing (test mode).");
      else {
        editSnippet(#1003674, newText);
        triggerTranspilerDirty();
        print(result += " Edited #1003674. Now " + countLines(newText) + " lines - " + n2(l(map)+1, "total class", "total classes") + "!");
      }
    } else {
      print(result = "Class " + 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 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1015881
Snippet name: addStdClass - Add a standard class to list (edits #1003674)
Eternal ID of this version: #1015881/12
Text MD5: 94752591b3a2a3b019ccc254aa2de618
Transpilation MD5: 7dda6d0211b79c0d03f99fa03acae078
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-25 18:09:10
Source code size: 1542 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 443 / 595
Version history: 11 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)