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

23
LINES

< > BotCompany Repo | #1028735 // tok_persistableClasses

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

Libraryless. Click here for Pure Java version (4759L/28K).

1  
// adds default constructor to classes with "persistable" modifier
2  
// also allows "persistent"
3  
svoid tok_persistableClasses(LS tok) {
4  
  int i;
5  
  
6  
  while((i = jfind_any(tok, tokCondition {
7  
    for (int j = i+1; isIdentifier(_get(tok, j)); j += 2)
8  
      if (eqGet(tok, j, "class"))
9  
        true;
10  
    false;
11  
  }, "persistable", "persistent")) >= 0) {
12  
    int iClass = indexOf(tok, "class", i);
13  
    S className = get(tok, iClass+2);
14  
    int idx = indexOf(tok, iClass, "{");
15  
    int j = findEndOfBracketPart(tok, idx);
16  
    L<S> contents = subList(tok, idx+1, j);
17  
    bool hasDefaultConstructor = tok_hasDefaultConstructor(contents, className);
18  
    printVars_str("tok_persistableClasses: ", +hasDefaultConstructor, +className);
19  
    if (!hasDefaultConstructor)
20  
      tokAppend_reTok(tok, idx, "\n  *() {}");
21  
    clearTokens_reTok(tok, i, i+2); // drop persistable keyword
22  
  }
23  
}

Author comment

Began life as a copy of #1012742

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028735
Snippet name: tok_persistableClasses
Eternal ID of this version: #1028735/8
Text MD5: 6d75c21f76b30360ef19cf6d96109f35
Transpilation MD5: 1258d21a9018e207bf8f65904acd0f57
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-30 04:32:48
Source code size: 893 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 238 / 357
Version history: 7 change(s)
Referenced in: [show references]