svoid tok_swappableFunctions(LS tok) { jreplace(tok, "swappable static", "static swappable"); jreplace(tok, "pswappable <id>", "persistently swappable $2"); int i; while ((i = jfind(tok, "swappable <id> <id>(")) >= 0) { int iModEnd = i; bool persistently = eqGet(tok, i-2, "persistently"); if (persistently) iModEnd -= 2; int iMod = leftScanModifiers(tok, iModEnd); S modifiers = joinSubList(tok, iMod, iModEnd); S returnType = tok.get(i+2), name = tok.get(i+4); int iCurly = indexOf(tok, i, "{"); LS tokArgs = subList(tok, i+7, iCurly-2); LPairS args = tok_typesAndNamesOfParams(tokArgs); S args1 = join(tokArgs); S args2 = joinWithComma(pairsB(args)); bool isVoidMethod = eq(returnType, "void"); LS types = pairsA(args); if (!isVoidMethod) types.add(returnType); S typeParams = joinWithComma(map tok_toNonPrimitiveTypes(types)); // TODO: modifiers S base = name + "_base"; S mods = modifiers + (persistently || containsJavaToken(modifiers, "static") ? "" : "transient "); S src; if (isVoidMethod) if (empty(args)) src = mods + "Runnable \*name*/;\n" + "\*modifiers*/\*returnType*/ \*name*/(\*args1*/) { if (\*name*/ != null) \*name*/.run(\*args2*/); else \*base*/(\*args2*/); }\n" + "\*modifiers*/\*returnType*/ \*base*/(\*args1*/) {"; else src = mods + "IVF\*l(args)*/<\*typeParams*/> \*name*/;\n" + "\*modifiers*/\*returnType*/ \*name*/(\*args1*/) { if (\*name*/ != null) \*name*/.get(\*args2*/); else \*base*/(\*args2*/); }\n" + "\*modifiers*/\*returnType*/ \*base*/(\*args1*/) {"; else src = mods + "IF\*l(args)*/<\*typeParams*/> \*name*/;\n" + "\*modifiers*/\*returnType*/ \*name*/(\*args1*/) { ret \*name*/ != null ? \*name*/.get(\*args2*/) : \*base*/(\*args2*/); }\n" + "\*modifiers*/\*returnType*/ \*base*/(\*args1*/) {"; replaceTokens_reTok(tok, iMod, iCurly+1, src); } }
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: | 178 / 212 |
Referenced in: | [show references] |