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

32
LINES

< > BotCompany Repo | #1005018 // Split single source into .java files [WORKS for simple cases, e.g. "Mocha Doom"]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1576L/11K/37K).

1  
!759
2  
3  
p {
4  
  S java = loadTextFile(getProgramFile("#1005014", "mochadoom.java"));
5  
  L<S> tok = javaTok(java);
6  
  L<Int> indexes = jfindAll(tok, "package");
7  
  if (empty(indexes) || indexes.get(0) != 1)
8  
    indexes.add(0, 1);
9  
  for i over indexes: {
10  
    int from = indexes.get(i);
11  
    int to = i+1 < l(indexes) ? indexes.get(i+1) : l(tok);
12  
    L<S> subtok = cncSubList(tok, from, to);
13  
    S src = join(subtok);
14  
    //print(shorten(src, 80));
15  
    S pack = tok_packageName(subtok);
16  
    print("Package: " + quote(pack));
17  
    L<L<S>> classes = allClasses(subtok);
18  
    for (L<S> c : classes) {
19  
      //print("  Class: " + shorten(join(c), 80));
20  
      print("  Class: " + quote(getClassDeclarationName(c)));
21  
    }
22  
    if (empty(classes))
23  
      print("No classes?? " + quote(src));
24  
    else if (l(classes) == 1) {
25  
      S fileName = addSlash(pack.replace('.', '/')) + getClassDeclarationName(first(classes)) + ".java";
26  
      print("File name: " + fileName);
27  
    } else
28  
      fail("Not supported");
29  
    print();
30  
    // TODO saveTextFile(getProgramFile("src", sourceName));
31  
  }
32  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005018
Snippet name: Split single source into .java files [WORKS for simple cases, e.g. "Mocha Doom"]
Eternal ID of this version: #1005018/1
Text MD5: ceafb741b48eb46aec5da58f402b14bc
Transpilation MD5: 27505f63467dda5b480957928495d8ac
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-09-28 21:49:22
Source code size: 1097 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 586 / 712
Referenced in: [show references]