1 | svoid tok_swappableFunctions(LS tok) { |
2 | jreplace(tok, "swappable static", "static swappable"); |
3 | jreplace(tok, "pswappable <id>", "persistently swappable $2"); |
4 | |
5 | int i; |
6 | while ((i = jfind(tok, "swappable <id> <id>(")) >= 0) { |
7 | int iModEnd = i; |
8 | bool persistently = eqGet(tok, i-2, "persistently"); |
9 | if (persistently) iModEnd -= 2; |
10 | int iMod = leftScanModifiers(tok, iModEnd); |
11 | S modifiers = joinSubList(tok, iMod, iModEnd); |
12 | S returnType = tok.get(i+2), name = tok.get(i+4); |
13 | int iCurly = indexOf(tok, i, "{"); |
14 | LS tokArgs = subList(tok, i+7, iCurly-2); |
15 | LPairS args = tok_typesAndNamesOfParams(tokArgs); |
16 | S args1 = join(tokArgs); |
17 | S args2 = joinWithComma(pairsB(args)); |
18 | bool isVoidMethod = eq(returnType, "void"); |
19 | LS types = pairsA(args); |
20 | if (!isVoidMethod) types.add(returnType); |
21 | S typeParams = joinWithComma(map tok_toNonPrimitiveTypes(types)); // TODO: modifiers |
22 | S base = name + "_base"; |
23 | S mods = modifiers + (persistently || containsJavaToken(modifiers, "static") ? "" : "transient "); |
24 | S src; |
25 | if (isVoidMethod) |
26 | if (empty(args)) |
27 | src = mods + "Runnable \*name*/;\n" + |
28 | "\*modifiers*/\*returnType*/ \*name*/(\*args1*/) { if (\*name*/ != null) \*name*/.run(\*args2*/); else \*base*/(\*args2*/); }\n" + |
29 | "\*modifiers*/\*returnType*/ \*base*/(\*args1*/) {"; |
30 | else |
31 | src = mods + "IVF\*l(args)*/<\*typeParams*/> \*name*/;\n" + |
32 | "\*modifiers*/\*returnType*/ \*name*/(\*args1*/) { if (\*name*/ != null) \*name*/.get(\*args2*/); else \*base*/(\*args2*/); }\n" + |
33 | "\*modifiers*/\*returnType*/ \*base*/(\*args1*/) {"; |
34 | else |
35 | src = mods + "IF\*l(args)*/<\*typeParams*/> \*name*/;\n" + |
36 | "\*modifiers*/\*returnType*/ \*name*/(\*args1*/) { ret \*name*/ != null ? \*name*/.get(\*args2*/) : \*base*/(\*args2*/); }\n" + |
37 | "\*modifiers*/\*returnType*/ \*base*/(\*args1*/) {"; |
38 | replaceTokens_reTok(tok, iMod, iCurly+1, src); |
39 | } |
40 | } |
Began life as a copy of #1026384
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1027652 |
Snippet name: | tok_swappableFunctions [v2, before fallback] |
Eternal ID of this version: | #1027652/1 |
Text MD5: | f4db02574b38f3ed74ff6bf9779efdc4 |
Author: | stefan |
Category: | javax / linux |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-29 19:09:39 |
Source code size: | 2011 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 180 / 214 |
Referenced in: | [show references] |