1 | // currently allows only one argument |
2 | svoid tok_mruCachedFunctions(LS tok) { pcall { |
3 | if (!tok.contains("mruCached")) ret; |
4 | int i = -1; |
5 | while ((i = jfind(tok, i+1, "static mruCached <id>")) >= 0) { |
6 | int iCurly = tok_findEndOfMethodHeader(tok, i); |
7 | LS tok2 = subList(tok, i); |
8 | S name = tok_methodName(tok2); |
9 | IntRange r = tok_findArgs(tok2); |
10 | LPair<S> typesAndNames = tok_typesAndNamesOfParams(subList(tok2, r)); |
11 | if (l(typesAndNames) != 1) print("mruCached function must have exactly one argument: " + name); |
12 | |
13 | S inputType = first(typesAndNames).b; |
14 | S boxedInputType = tok_toNonPrimitiveTypes(inputType); |
15 | |
16 | S returnType = joinSubList(tok, i+4, bracket-3); |
17 | S boxedReturnType = tok_toNonPrimitiveTypes(returnType); |
18 | |
19 | replaceTokens(tok2, i, bracket-1, |
20 | "static \*boxedType*/ \*fName*/_cache;\n" |
21 | + "static \*type*/ \*fName*/() { if (\*fName*/_cache == null) \*fName*/_cache = \*fName*/_load(); ret \*fName*/_cache; }\n\n" + "static \*boxedType*/ \*fName*/_load"); |
22 | reTok(tok, i, iCurly); |
23 | } |
24 | }} |
Began life as a copy of #1020989
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1024403 |
Snippet name: | tok_mruCachedFunctions [dev.] |
Eternal ID of this version: | #1024403/1 |
Text MD5: | d73ecb5e564d9b049861c88ee1fcf15d |
Author: | stefan |
Category: | javax / transpiling |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-08-10 14:33:26 |
Source code size: | 1070 bytes / 24 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 189 / 227 |
Referenced in: | [show references] |