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

14
LINES

< > BotCompany Repo | #1020989 - tok_simplyCachedFunctions

JavaX fragment (include)

static void tok_simplyCachedFunctions(L<S> tok) { pcall {
  if (!tok.contains("simplyCached")) ret;
  int i = -1;
  while ((i = jfind(tok, i+1, "static simplyCached <id>")) >= 0) {
    int bracket = indexOf(tok, "(", i);
    S fName = assertIdentifier(tok.get(bracket-2));
    S type = joinSubList(tok, i+4, bracket-3);
    S boxedType = tok_toNonPrimitiveTypes(type);
    
    replaceTokens(tok, 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, bracket-3);
  }
}}

Author comment

Began life as a copy of #1010513

download  show line numbers  debug dex   

Travelled to 4 computer(s): cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1020989
Snippet name: tok_simplyCachedFunctions
Eternal ID of this version: #1020989/8
Text MD5: 98d02190849364f8898f58da2d61ed55
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-03 15:38:25
Source code size: 676 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 80 / 104
Version history: 7 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1020989 & http://1020989.tinybrain.de