1 | !636 |
2 | !quicktranslator |
3 | !class JavaTok |
4 | |
5 | // expand shortened constructor syntax: |
6 | // *(...) { ... } |
7 | // to |
8 | // MyClass(...) { ... } |
9 | |
10 | List<String> tok = JavaTok.split(s); |
11 | mainLoop: for (int i = 3; i+6 < tok.size(); i += 2) { |
12 | String t = tok.get(i), l = tok.get(i-2); |
13 | if (!t.equals("*")) |
14 | continue; |
15 | if (!tok.get(i+2).equals("(")) |
16 | continue; |
17 | if (!l.equals("}") && !l.equals(";")) // is this correct...?? |
18 | continue; |
19 | |
20 | // ok, it seems like a constructor declaration. |
21 | // Now find class name by going backwards. |
22 | |
23 | int j = i, level = 1; |
24 | while (j > 0 && level > 0) { |
25 | t = tok.get(j); |
26 | if (t.equals("}")) ++level; |
27 | if (t.equals("{")) --level; |
28 | j -= 2; |
29 | } |
30 | |
31 | while (j > 0) { |
32 | t = tok.get(j); |
33 | if (t.equals("class")) { |
34 | String className = tok.get(j+2); |
35 | tok.set(i, className); // done! |
36 | continue mainLoop; |
37 | } |
38 | j -= 2; |
39 | } |
40 | } |
41 | s = JavaTok.join(tok); |
Began life as a copy of #1000381
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
ID | Author/Program | Comment | Date | |
---|---|---|---|---|
618 | #1000610 | Edit suggestion: !636 !629 main { static Object androidContext; static String programID; public static void main(String[] args) throws Exception { !636 !quicktranslator !class JavaTok // expand shortened constructor syntax: // *(...) { ... } // to // MyClass(...) { ... } List<String> tok = JavaTok.split(s); mainLoop: for (int i = 3; i+6 < tok.size(); i += 2) { String t = tok.get(i), l = tok.get(i-2); if (!t.equals("*")) continue; if (!tok.get(i+2).equals("(")) continue; if (!l.equals("}") && !l.equals(";")) // is this correct...?? continue; // ok, it seems like a constructor declaration. // Now find class name by going backwards. int j = i, level = 1; while (j > 0 && level > 0) { t = tok.get(j); if (t.equals("}")) ++level; if (t.equals("{")) --level; j -= 2; } while (j > 0) { t = tok.get(j); if (t.equals("class")) { String className = tok.get(j+2); tok.set(i, className); // done! continue mainLoop; } j -= 2; } } s = JavaTok.join(tok); }} | 2015-08-19 00:55:38 | delete |
616 | #1000604 (pitcher) | 2015-08-18 00:07:22 |
Snippet ID: | #696 |
Snippet name: | "*" constructor syntax (translator) |
Eternal ID of this version: | #696/1 |
Text MD5: | 63e0ba9f5897f4cd80065d3d78621c86 |
Author: | stefan |
Category: | javax |
Type: | JavaX translator |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-07-31 15:15:46 |
Source code size: | 942 bytes / 41 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 1320 / 1064 |
Referenced in: | [show references] |