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

33
LINES

< > BotCompany Repo | #1001362 // Named thread: thread "bla" {

JavaX translator [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (478L/4K/13K).

1  
// Syntax: thread "bla" { doSomething(); }
2  
// Also: thread var { doSomething(); }
3  
// Short for: new Thread("bla) { public void run() { doSomething(); }}.start();
4  
5  
!747
6  
7  
m {
8  
  p {
9  
    L<S> tok = javaTok(loadMainJava());
10  
    
11  
    for (int i = 0; i < 100; i++) {
12  
      int idx = findCodeTokens(tok, "thread", "*", "{");
13  
      if (idx < 0)
14  
        break;
15  
      int j = findEndOfBracketPart(tok, idx+4);
16  
      S tName = tok.get(idx+2);
17  
      
18  
      S var = "_t_" + i;
19  
      S pre = "{ Thread " + var + " = new Thread(" + tName + ") {\n" +
20  
        "public void run() {\n" +
21  
        "try";
22  
      S post = "} catch (Exception _e) {\n" +
23  
          "  throw _e instanceof RuntimeException ? (RuntimeException) _e : new RuntimeException(_e); } }\n};\n" +
24  
        var + ".start(); }";
25  
26  
      tok.set(idx, pre);
27  
      tok.set(idx+2, "");
28  
      tok.set(j-1, post);
29  
    }
30  
    
31  
    saveMainJava(join(tok));
32  
  }
33  
}

Author comment

Began life as a copy of #721

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: #1001362
Snippet name: Named thread: thread "bla" {
Eternal ID of this version: #1001362/1
Text MD5: 076d9ceae50fbb2ca872f827ecf2fd49
Transpilation MD5: e1a3af5563f17c04636eb03ea301b282
Author: stefan
Category:
Type: JavaX translator
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-24 14:23:14
Source code size: 928 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 622 / 2509
Referenced in: [show references]