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
2 comment(s) hidden. show
| 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: | 2124 / 1859 |
| Referenced in: | [show references] |