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

18
LINES

< > BotCompany Repo | #1020989 - tok_simplyCachedFunctions

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3119L/20K).

static void tok_simplyCachedFunctions(L<S> tok) { pcall {
  if (!tok.contains("simplyCached")) ret;
  int i = -1;
  while ((i = jfind(tok, i+1, "simplyCached <id>")) >= 0) {
    Cl<S> modifiers = tok_modifiersLeftOf(tok, i);
    int bracket = indexOf(tok, "(", i);
    S fName = assertIdentifier(tok.get(bracket-2));
    S type = joinSubList(tok, i+2, bracket-3);
    S boxedType = tok_toNonPrimitiveTypes(type);
    S mods2 = joinWithSpace(listMinus(modifiers, "transient"));
    
    // we keep the modifiers (e.g. static, transient) for the variable
    // the function gets the modifiers minus "transient"
    replaceTokens(tok, i, bracket-1, "\*boxedType*/ \*fName*/_cache;\n"
      + "\*mods2*/ \*type*/ \*fName*/() { if (\*fName*/_cache == null) \*fName*/_cache = \*fName*/_load(); ret \*fName*/_cache; }\n\n" + "\*mods2*/ \*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 5 computer(s): cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1020989
Snippet name: tok_simplyCachedFunctions
Eternal ID of this version: #1020989/11
Text MD5: 32c7420c74401f7ceac1a6aad2179e66
Transpilation MD5: 9d1b19da9f0ba6d14b8a0656ee0fd7d2
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-05-18 20:11:23
Source code size: 915 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 124 / 182
Version history: 10 change(s)
Referenced in: [show references]

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