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).

// Syntax: stringFunc { s.trim() }

!592 629 // auto-importer, standard function adder 
!723 // L<S>
!680 // quicknew

public class main {
  public static void main(String[] args) throws Exception {
    L<S> tok = javaTok(loadMainJava());
    
    for (int i = 0; i < 100; i++) {
      int idx = findCodeTokens(tok, "stringfunc", "{");
      if (idx < 0)
        break;
        
      int j = findEndOfBracketPart(tok, idx+2);
      
      tok.set(idx, "new StringFunc() {\n" +
        "public String get(String s) {\n" +
        "try { return ");
      tok.set(idx+2, "");
      tok.set(j-1, "; } catch (Exception _e) {\n" +
          "  throw _e instanceof RuntimeException ? (RuntimeException) _e : new RuntimeException(_e); } } }");
    }

    // add interface to main class
    
    L<S> c = findMainClass(tok);
    
    if (join(c).indexOf("interface StringFunc") < 0)
      c.set(c.size()-2, "static interface StringFunc {\n" +
        "  String get(String s);\n" +
        "}\n" +
        "}");
    
    saveMainJava(join(tok));
  }
}

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: 794 / 1957
Referenced in: #636 - Resolve symbolic translator invocations
#1000634 - Spike - find table names in MySQL dump
#1000636 - Compare strings with "==" instead of "equals" (JavaX translator)
#1000642 - Find create statements in MySQL dump
#1000648 - Find field names in MySQL "create table"
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)