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

121
LINES

< > BotCompany Repo | #1030951 // Add functions and classes to Gazelle BEA Loadable Utils [OK]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1113K of libraries. Click here for Pure Java version (8504L/47K).

1  
!7
2  
3  
/*
4  
How to:
5  
-use "transpile debug" on #1031393, copy output into #1030949
6  
-Press the "do it" button
7  
-Manually add lambdaMapLike etc to #1030953
8  
-Check that things still work
9  
*/
10  
11  
cprint {
12  
  transient Set<S> requestedFunctions, requestedClasses;
13  
  transient Set<S> have, haveClasses;
14  
  transient new Set<S> blockedFunctions;
15  
  transient new Set<S> blockedClasses;
16  
  transient Set<S> newFunctions, newClasses;
17  
  transient new Set<S> imported;
18  
  transient Set<S> importedClasses;
19  
  transient Set<S> toImport, classesToImport;
20  
  transient new SS modifiers;
21  
  
22  
  transient S loadableUtilsSnippetID = #1030952;
23  
  transient S includeSnippetID = #1030953;
24  
  transient S globalSnippetID = #1020737;
25  
  transient S transpilerOutputSnippetID = #1030949;
26  
  
27  
  visual
28  
    withCenteredButtons(super,
29  
      jButton("Do it", rThreadEnter doIt));
30  
  
31  
  start-thread {
32  
    LS transpilerLines = mapLines(loadSnippet(transpilerOutputSnippetID), s -> dropLeadingAngleBracketStuff(s));
33  
    requestedFunctions = asSet(startingWithIC_dropAndTrim("Compiling function:", transpilerLines);
34  
    requestedClasses = asSet(startingWithIC_dropAndTrim("Compiling class:", transpilerLines);
35  
    
36  
    print(n2(requestedFunctions, "requested function"));
37  
    print(n2(requestedClasses, "requested class", "requested classes"));
38  
    
39  
    for (PairS p : parseColonPropertyPairs(lines(transpilerLines)))
40  
      if (eqOneOf(p.a, "mapLike", "mapMethodLike", "nuLike", "lambdaMapLike", "curry1Like"))
41  
        modifiers.put(p.b, p.a);
42  
    print(n2(modifiers, "function modifier"));
43  
        
44  
    S text = loadSnippet(loadableUtilsSnippetID);
45  
    have = asSet(lmap tok_lastIdentifier(jextractAll("please include function <id>.", text)));
46  
    haveClasses = asSet(lmap tok_lastIdentifier(jextractAll("please include class <id>.", text)));
47  
    
48  
    print("Have " + n2(have, "function"));
49  
    
50  
    S includeSnippet = joinNemptiesWithEmptyLines(
51  
      loadSnippet(includeSnippetID),
52  
      loadSnippet(globalSnippetID));
53  
    
54  
    new Matches m;
55  
    for (S comment : trimAll(getJavaLineComments(text))) {
56  
      if (find3("don't include function *", comment, m))
57  
        blockedFunctions.add($1);
58  
      if (find3("don't include class *", comment, m))
59  
        blockedClasses.add($1);
60  
    }
61  
        
62  
    for (S comment : trimAll(getJavaLineComments(includeSnippet)))
63  
      if (swic(comment, "don't import "))
64  
        blockedFunctions.add(tok_lastIdentifier(comment));
65  
        
66  
    for (S s : jextractAll(javaTok(includeSnippet), "please include function <id>."))
67  
      blockedFunctions.add(tok_lastIdentifier(s));
68  
      
69  
    print(n2(blockedFunctions, "blocked function") + ": " + blockedFunctions);
70  
    print(n2(blockedClasses, "blocked class", "blocked classes") + ": " + blockedClasses);
71  
    
72  
    newFunctions = setMinusSet(setMinusSet(requestedFunctions, blockedFunctions), have);
73  
    print(n2(newFunctions, "new function"));
74  
    
75  
    newClasses = setMinusSet(setMinusSet(requestedClasses, blockedClasses), haveClasses);
76  
    print(n2(newClasses, "new class", "new classes"));
77  
    
78  
    for (S s : tlft(includeSnippet)) {
79  
      s = simpleSpaces(s);
80  
      if (startsWith(s, "import static "))
81  
        imported.add(tok_lastIdentifier(s));
82  
    }
83  
    print(n2(imported, "imported function"));
84  
    
85  
    importedClasses = asSet(lmap tok_lastIdentifier(jextractAll("import loadableUtils.utils.<id>;", includeSnippet)));
86  
    print(n2(importedClasses, "imported class", "imported classes"));
87  
    
88  
    toImport = setMinusSet(setMinusSet(have, imported), blockedFunctions);
89  
    print(n2(toImport) + " function(s) to import");
90  
    
91  
    classesToImport = setMinusSet(haveClasses, importedClasses);
92  
    print(n2(classesToImport) + " class(es) to import");
93  
  }
94  
  
95  
  // appends to Loadable Utils snippet
96  
  void appendThem {
97  
    if (empty(newFunctions) && empty(newClasses)) ret with print("Nothing to do");
98  
    S text = loadSnippet(loadableUtilsSnippetID);
99  
    text += "\n\n"
100  
      + mapToLines(newFunctions, f -> "please include function " + f + ".")
101  
      + mapToLines(newClasses, c -> "please include class " + c + ".");
102  
    editSnippet(loadableUtilsSnippetID, text);
103  
  }
104  
  
105  
  // appends to Compact Module Include
106  
  void appendImported {
107  
    if (empty(toImport) && empty(classesToImport)) ret with print("Nothing to do");
108  
    S text = loadSnippet(includeSnippetID);
109  
    text += "\n\n"
110  
      + mapToLines(toImport, f -> "import static loadableUtils.utils."
111  
        + appendSpaceIfNempty(modifiers.get(f))
112  
        + f + ";")
113  
      + mapToLines(classesToImport, c -> "import loadableUtils.utils." + c + ";");
114  
    editSnippet(includeSnippetID, text);
115  
  }
116  
  
117  
  void doIt {
118  
    appendThem();
119  
    appendImported();
120  
  }
121  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030951
Snippet name: Add functions and classes to Gazelle BEA Loadable Utils [OK]
Eternal ID of this version: #1030951/27
Text MD5: 8c1c1f66cdb5c7688c07f2e2fa9442af
Transpilation MD5: 361dd1a27598c986e74115b4e573f3db
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-18 16:52:57
Source code size: 4766 bytes / 121 lines
Pitched / IR pitched: No / No
Views / Downloads: 173 / 417
Version history: 26 change(s)
Referenced in: [show references]