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

32
LINES

< > BotCompany Repo | #1001157 // allClasses [works on tokenization, also finds enum and interface and most JavaX constructs]

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

Libraryless. Click here for Pure Java version (3755L/21K).

1  
static HashSet<S> allClasses_keywords = lithashset("class", "interface", "enum", "sclass", "sinterface", "record", "srecord", "strecord", "asclass", "concept");
2  
3  
// lists returned are actual CNC (N/C/N/.../C/N) - and connected to
4  
// original list
5  
// only returns the top level classes
6  
static LL<S> allClasses(L<S> tok) {
7  
  LL<S> l = new ArrayList;
8  
  int n = tok.size();
9  
  HashSet<S> _allClasses_keywords = allClasses_keywords;
10  
  for (int i = 1; i < n; i += 2) {
11  
    S t = tok.get(i);
12  
    if ("{".equals(t)) // skip functions
13  
      i = findEndOfBlock(tok, i)-1;
14  
    else if (_allClasses_keywords.contains(t)
15  
      && (tok_isJavaxMetaCommandLeftOf(tok, i) ||
16  
        !(eqGetOneOf(tok, i-2, ".", "include")
17  
          && !containsNewLine(tok.get(i-1))))) {
18  
      int j = i;
19  
      while (j < n && !tok.get(j).equals("{"))
20  
        j += 2;
21  
      j = findEndOfBlock(tok, j)+1;
22  
      i = leftScanModifiers(tok, i);
23  
      l.add(subList(tok, i-1, Math.min(n, j)));
24  
      i = j-2;
25  
    }
26  
  }
27  
  ret l;
28  
}
29  
30  
static LL<S> allClasses(S text) {
31  
  ret allClasses(javaTok(text));
32  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1001157
Snippet name: allClasses [works on tokenization, also finds enum and interface and most JavaX constructs]
Eternal ID of this version: #1001157/19
Text MD5: 729b47a0cb00159c19728bcef278e120
Transpilation MD5: 6d13407a06b677ff5397465c93e15255
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-21 00:34:46
Source code size: 1090 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 802 / 2553
Version history: 18 change(s)
Referenced in: [show references]