!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 l = toLines(s); new List x; Pattern p = Pattern.compile("^\\s*import\\s"); for (ListIterator 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); } }