Libraryless. Click here for Pure Java version (131L/2K/5K).
1 | // Syntax: awt { doSomethingInAwtThread(); } |
2 | |
3 | !592 1000265 // auto-importer, standard function adder |
4 | |
5 | public class main { |
6 | public static void main(String[] args) throws Exception { |
7 | String s = loadMainJava(); |
8 | |
9 | Pattern regex = Pattern.compile("(awt)\\s*\\{"); |
10 | |
11 | for (int i = 0; i < 100; i++) { |
12 | Matcher matcher = regex.matcher(s); |
13 | if (!matcher.find()) |
14 | break; |
15 | |
16 | int start = matcher.start(), end = matcher.end(); |
17 | int endOfBlock = findEndOfBlock(s, end); |
18 | boolean daemon = matcher.group().startsWith("d"); |
19 | |
20 | String code = "SwingUtilities.invokeLater(new Runnable() {\n" + |
21 | "public void run() {\n" + |
22 | "try {\n" + |
23 | s.substring(end, endOfBlock) + "} catch (Exception _e) {\n" + |
24 | " throw _e instanceof RuntimeException ? (RuntimeException) _e : new RuntimeException(_e); } }\n});"; |
25 | s = s.substring(0, start) + code + s.substring(endOfBlock+1); |
26 | } |
27 | |
28 | saveMainJava(s); |
29 | } |
30 | |
31 | // start is the index AFTER the opening bracket |
32 | // returns index OF closing bracket |
33 | static int findEndOfBlock(String s, int start) { |
34 | int level = 1; |
35 | for (int i = start; i < s.length(); i++) { |
36 | if (s.charAt(i) == '{') ++level; |
37 | else if (s.charAt(i) == '}') --level; |
38 | if (level == 0) |
39 | return i; |
40 | } |
41 | return s.length(); |
42 | } |
43 | } |
Began life as a copy of #721
download show line numbers debug dex old transpilations
Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, dhtvkmknsjym, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000805 |
Snippet name: | "awt {" (JavaX translator) |
Eternal ID of this version: | #1000805/1 |
Text MD5: | f4eb02052da300952c1a7052261b9b5d |
Transpilation MD5: | 9004a9598c3a2e5f528a2280f9b495c3 |
Author: | stefan |
Category: | |
Type: | JavaX translator |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-01-29 18:38:35 |
Source code size: | 1382 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 848 / 4815 |
Referenced in: | [show references] |