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

31
LINES

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

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

Transpiled version (2658L) is out of date.

static HashSet<S> allClasses_keywords = lithashset("class", "interface", "enum", "sclass", "sinterface", "record", "srecord", "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"))) {
      int j = i;
      while (j < n && !tok.get(j).equals("{"))
        j += 2;
      j = findEndOfBlock(tok, j)+1;
      i = leftScanModifiers(tok, i);
      l.add(tok.subList(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   

Travelled to 11 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, tslmcundralx, tvejysmllsmz

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/15
Text MD5: 87cf3384fbe638094437c50669b60468
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-23 22:38:52
Source code size: 1030 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 448 / 2013
Version history: 14 change(s)
Referenced in: [show references]

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