Transpiled version (11385L) is out of date.
1 | // example: |
2 | // sS loadTextFile(File/S file) { ... }
|
3 | |
4 | svoid tok_multiTypeArguments_v2(LS tok) {
|
5 | int i; |
6 | |
7 | // File/S |
8 | |
9 | while ((i = jfind(tok, "File/<id> <id>", (_tok, nIdx) -> |
10 | eqGetOneOf(_tok, nIdx+5, "S", "String"))) >= 0) {
|
11 | |
12 | S argName = tok.get(i+6); |
13 | S mainType = tok.get(i), altType = tok.get(i+4); |
14 | S converter = "newFile"; |
15 | S expr = converter + "(" + argName + ")";
|
16 | |
17 | tok_expandMultiTypeArgument(tok, |
18 | i, i+8, |
19 | argName, |
20 | mainType, altType, expr); |
21 | } |
22 | |
23 | // Graphics2D etc, IIntegralImage etc, ... |
24 | |
25 | while ((i = jfind(tok, "<id> etc <id>")) >= 0) {
|
26 | S mainType = tok.get(i); |
27 | S argName = tok.get(i+4); |
28 | int iArgEnd = i+6; |
29 | |
30 | new LPairS alts; // altType, converter |
31 | bool v3; |
32 | if (eq(mainType, "Graphics2D")) |
33 | alts.add(pair("BufferedImage", "graphics"));
|
34 | else if (eq(mainType, "File")) |
35 | alts.add(pair("String", "toFile"));
|
36 | else if (eq(mainType, "BWImage")) |
37 | alts.add(pair("BufferedImage", "toBWImage"));
|
38 | else if (eq(mainType, "IIntegralImage")) {
|
39 | alts.add(pair("BufferedImage", "IntegralImage"));
|
40 | alts.add(pair("MakesBufferedImage", "IntegralImage"));
|
41 | } else if (eq(mainType, "BufferedImage")) |
42 | alts.add(pair("MakesBufferedImage", "toBufferedImage"));
|
43 | else if (eq(mainType, "Runnable")) |
44 | alts.add(pair("IF0", "if0ToRunnable"));
|
45 | else if (eq(mainType, "Component")) |
46 | alts.add(pair("Swingable", "toComponent"));
|
47 | else if (eq(mainType, "JComponent")) |
48 | alts.add(pair("Swingable", "toJComponent"));
|
49 | else if (eq(mainType, "WidthAndHeight")) {
|
50 | alts.add(pair("Dimension", "toWidthAndHeight"));
|
51 | alts.add(pair("int \*argName*/_w, int \*argName*/_h",
|
52 | "widthAndHeight(\*argName*/_w, \*argName*/_h)")); |
53 | set v3; |
54 | } else if (eq(mainType, "Pt")) {
|
55 | alts.add(pair("int \*argName*/_x, int \*argName*/_y",
|
56 | "pt(\*argName*/_x, \*argName*/_y)")); |
57 | set v3; |
58 | } else if (eqOneOf(mainType, "DoublePt", "IDoublePt")) {
|
59 | alts.add(pair("double \*argName*/_x, double \*argName*/_y",
|
60 | "doublePt(\*argName*/_x, \*argName*/_y)")); |
61 | set v3; |
62 | } |
63 | |
64 | if (empty(alts)) |
65 | fail("Unknown multi-type: " + joinSubList(tok, i, iArgEnd));
|
66 | |
67 | if (v3) |
68 | tok_expandMultiTypeArgument_v3(tok, |
69 | i, iArgEnd, |
70 | argName, |
71 | mainType, alts); |
72 | else |
73 | tok_expandMultiTypeArgument_v2(tok, |
74 | i, iArgEnd, |
75 | argName, |
76 | mainType, alts); |
77 | } |
78 | |
79 | // Iterable<X> or X[], Iterable<> or X... |
80 | |
81 | IntRange r; |
82 | for (S modifier : ll("[]", "..."))
|
83 | while ((r = jfind_range(tok, "Iterable<<id>> or <id>" + modifier + " <id>")) != null) {
|
84 | i = r.start+1; |
85 | S mainType = joinSubList(tok, i, i+7); |
86 | S altType = joinSubList(tok, i+10, r.end-3); |
87 | S argName = tok.get(r.end-2); |
88 | S converter = "asList"; |
89 | S expr = converter + "(" + argName + ")";
|
90 | |
91 | tok_expandMultiTypeArgument(tok, i, r.end, argName, mainType, altType, expr); |
92 | } |
93 | |
94 | // Iterable or O[], Iterable or X..., Cl/O[], etc |
95 | |
96 | for (S modifier : ll("[]", "..."))
|
97 | while ((r = jfind_range(tok, "<id> * *" + modifier + " <id>", func(LS tok, int nIdx) {
|
98 | eqOneOf(tok.get(nIdx+1), "Iterable", "Collection", "Cl", "List", "L") |
99 | && eqGetOneOf(tok, nIdx+3, "or", "/") |
100 | && eqGetOneOf(tok, nIdx+5, "O", "Object") |
101 | })) != null) {
|
102 | i = r.start+1; |
103 | S mainType = tok.get(i); |
104 | S altType = joinSubList(tok, i+4, r.end-3); |
105 | S argName = tok.get(r.end-2); |
106 | S converter = "asList"; |
107 | S expr = converter + "(" + argName + ")";
|
108 | |
109 | tok_expandMultiTypeArgument(tok, i, r.end, argName, mainType, altType, expr); |
110 | } |
111 | } |
Began life as a copy of #1031905
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
| Snippet ID: | #1032173 |
| Snippet name: | tok_multiTypeArguments_v2 [certain multi-typed arguments for functions, run after most JavaX translations, LIVE] |
| Eternal ID of this version: | #1032173/36 |
| Text MD5: | e1bb6231943cf0303950d48ea79fbd0f |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-12-17 15:01:08 |
| Source code size: | 3790 bytes / 111 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 615 / 852 |
| Version history: | 35 change(s) |
| Referenced in: | [show references] |