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

20
LINES

< > BotCompany Repo | #1025861 // tok_timedCachedFunctions - use class TimedCache (single object cache)

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

Libraryless. Click here for Pure Java version (3577L/22K).

static void tok_timedCachedFunctions(LS tok) { pcall {
  int i;
  while ((i = jfind(tok, "timedCached[<int>.<int>] <id>")) >= 0) {
    int bracket1 = indexOf(tok, "]", i);
    S time = joinSubList(tok, i+4, bracket1-1);
    int bracket = indexOf(tok, "(", bracket1);
    S fName = assertIdentifier(tok.get(bracket-2));
    S type = joinSubList(tok, bracket1+2, bracket-3);
    S boxedType = tok_toNonPrimitiveTypes(type);
    var modifiersList = tok_modifiersLeftOf(tok, i);
    S modifiers = joinWithSpace(modifiersList);
    S functionModifiers = joinWithSpace(listMinus(modifiersList, "transient"));
    
    replaceTokens(tok, i, bracket-1,
      "TimedCache<\*boxedType*/> \*fName*/_cache = new <>(\*time*/, lambda0 \*fName*/_load);\n"
      + "\*functionModifiers*/ \*type*/ \*fName*/() { ret \*fName*/_cache!; }\n\n"
      + "\*functionModifiers*/ \*boxedType*/ \*fName*/_load");
    reTok(tok, i, bracket-3);
  }
}}

Author comment

Began life as a copy of #1010513

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: #1025861
Snippet name: tok_timedCachedFunctions - use class TimedCache (single object cache)
Eternal ID of this version: #1025861/13
Text MD5: ce181d3fe34af23495806475024be8b0
Transpilation MD5: bea316d051d7de41c7d8380a45d253a2
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-26 20:24:48
Source code size: 942 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 281 / 432
Version history: 12 change(s)
Referenced in: [show references]