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

38
LINES

< > BotCompany Repo | #1000635 // "stringfunc {" (JavaX translator)

JavaX translator [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (304L/3K/9K).

1  
// Syntax: stringFunc { s.trim() }
2  
3  
!592 629 // auto-importer, standard function adder 
4  
!723 // L<S>
5  
!680 // quicknew
6  
7  
public class main {
8  
  public static void main(String[] args) throws Exception {
9  
    L<S> tok = javaTok(loadMainJava());
10  
    
11  
    for (int i = 0; i < 100; i++) {
12  
      int idx = findCodeTokens(tok, "stringfunc", "{");
13  
      if (idx < 0)
14  
        break;
15  
        
16  
      int j = findEndOfBracketPart(tok, idx+2);
17  
      
18  
      tok.set(idx, "new StringFunc() {\n" +
19  
        "public String get(String s) {\n" +
20  
        "try { return ");
21  
      tok.set(idx+2, "");
22  
      tok.set(j-1, "; } catch (Exception _e) {\n" +
23  
          "  throw _e instanceof RuntimeException ? (RuntimeException) _e : new RuntimeException(_e); } } }");
24  
    }
25  
26  
    // add interface to main class
27  
    
28  
    L<S> c = findMainClass(tok);
29  
    
30  
    if (join(c).indexOf("interface StringFunc") < 0)
31  
      c.set(c.size()-2, "static interface StringFunc {\n" +
32  
        "  String get(String s);\n" +
33  
        "}\n" +
34  
        "}");
35  
    
36  
    saveMainJava(join(tok));
37  
  }
38  
}

Author comment

Began life as a copy of #721

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, hxnwyiuffukg, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000635
Snippet name: "stringfunc {" (JavaX translator)
Eternal ID of this version: #1000635/1
Text MD5: 711402167ab82a5432abe7145ab2204d
Transpilation MD5: c75062b65375830de197d6b47eea1943
Author: stefan
Category:
Type: JavaX translator
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-30 18:39:07
Source code size: 1079 bytes / 38 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 795 / 1958
Referenced in: [show references]