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

37
LINES

< > BotCompany Repo | #713 // "quickandroid"

JavaX translator

!636
!standard functions
!quicknew

public class main {
  static String prelude =
    "public class main {\n" +
    "  static android.app.Activity androidContext; // set from outside\n" +
    "  public static void main(String[] args) throws Exception {\n";
  static String postlude = "\n" +
    "  }\n" +
    "}\n";

  public static void main(String[] args) throws IOException {
    String code = loadTextFile("input/main.java", null);
    if (code == null)
      throw new RuntimeException("Nothing to do (no input/main.java)");
    code = prelude + code + postlude;
    code = moveImportsUp(code);
    saveTextFile("output/main.java", code);
  }

  static String moveImportsUp(String s) {
    List<String> l = toLines(s);
    new List<String> x;
    Pattern p = Pattern.compile("^\\s*import\\s");
    for (ListIterator<String> i = l.listIterator(); i.hasNext(); ) {
      String line = i.next();
      if (p.matcher(line).find()) {
        x.add(line);
        i.remove();
      }
    }
    x.addAll(l);
    return fromLines(x);
  }
}

Author comment

Began life as a copy of #609

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #713
Snippet name: "quickandroid"
Eternal ID of this version: #713/1
Text MD5: 9d78782e9e276ba28b0f672adb16d00e
Author: stefan
Category:
Type: JavaX translator
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-06 22:30:50
Source code size: 1072 bytes / 37 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 591 / 504
Referenced in: [show references]