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).

static HashSet<S> allClasses_keywords = lithashset("class", "interface", "enum", "sclass", "sinterface", "record", "srecord", "strecord", "asclass", "concept");

// lists returned are actual CNC (N/C/N/.../C/N) - and connected to
// original list
// only returns the top level classes
static LL<S> allClasses(L<S> tok) {
  LL<S> l = new ArrayList;
  int n = tok.size();
  HashSet<S> _allClasses_keywords = allClasses_keywords;
  for (int i = 1; i < n; i += 2) {
    S t = tok.get(i);
    if ("{".equals(t)) // skip functions
      i = findEndOfBlock(tok, i)-1;
    else if (_allClasses_keywords.contains(t)
      && (tok_isJavaxMetaCommandLeftOf(tok, i) ||
        !(eqGetOneOf(tok, i-2, ".", "include")
          && !containsNewLine(tok.get(i-1))))) {
      int j = i;
      while (j < n && !tok.get(j).equals("{"))
        j += 2;
      j = findEndOfBlock(tok, j)+1;
      i = leftScanModifiers(tok, i);
      l.add(subList(tok, i-1, Math.min(n, j)));
      i = j-2;
    }
  }
  ret l;
}

static LL<S> allClasses(S text) {
  ret allClasses(javaTok(text));
}

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: 801 / 2552
Version history: 18 change(s)
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1005504 - allVarNames - find all variable/field declarations in a block/class
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)