Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

24
LINES

< > BotCompany Repo | #1024403 // tok_mruCachedFunctions [dev.]

JavaX fragment (include)

// currently allows only one argument
svoid tok_mruCachedFunctions(LS tok) { pcall {
  if (!tok.contains("mruCached")) ret;
  int i = -1;
  while ((i = jfind(tok, i+1, "static mruCached <id>")) >= 0) {
    int iCurly = tok_findEndOfMethodHeader(tok, i);
    LS tok2 = subList(tok, i);
    S name = tok_methodName(tok2);
    IntRange r = tok_findArgs(tok2);
    LPair<S> typesAndNames = tok_typesAndNamesOfParams(subList(tok2, r));
    if (l(typesAndNames) != 1) print("mruCached function must have exactly one  argument: " + name);

    S inputType = first(typesAndNames).b;
    S boxedInputType = tok_toNonPrimitiveTypes(inputType);

    S returnType = joinSubList(tok, i+4, bracket-3);
    S boxedReturnType = tok_toNonPrimitiveTypes(returnType);
    
    replaceTokens(tok2, i, bracket-1,
      "static \*boxedType*/ \*fName*/_cache;\n"
      + "static \*type*/ \*fName*/() { if (\*fName*/_cache == null) \*fName*/_cache = \*fName*/_load(); ret \*fName*/_cache; }\n\n" + "static \*boxedType*/ \*fName*/_load");
    reTok(tok, i, iCurly);
  }
}}

Author comment

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: 190 / 227
Referenced in: