Libraryless. Click here for Pure Java version (5294L/30K).
static LS findFunctionDefs(S s) { ret findFunctionDefs(javaTok(s)); } static L<S> findFunctionDefs(L<S> tok) { new LS functions; var keywords = findFunctionDefs_keywords(); if (tok instanceof IContentsIndexedList2) { for (S keyword : keywords) { TreeSet<HasIndex> indices = tok/IContentsIndexedList2.indicesOf_treeSetOfHasIndex(keyword); if (indices != null) for (HasIndex i : indices) findFunctionDefs_step(tok, i.idx, functions); } } else { int n = l(tok); for (int i = 1; i < n; i += 2) if (keywords.contains(tok.get(i))) findFunctionDefs_step(tok, i, functions); } ret functions; } // we found one of the keywords listed above at token i // now scan forward for a function definition svoid findFunctionDefs_step(LS tok, int i, LS functions) { S t = tok.get(i); int j = i+2, n = l(tok); while (j < n && !findFunctionsDefs_checkToken(tok.get(j))) j += 2; if (isIdentifier(tok.get(j-2)) && eqGet(tok, j, "(") || eqGet(tok, j, "{") && eq(t, "svoid")) functions.add(tok.get(j-2)); } sbool findFunctionsDefs_checkToken(S t) { if (t.length() != 1) false; char c = t.charAt(0); ret c == ';' || c == '=' || c == '(' || c == '{' /*|| c == '#' XXX*/; }
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
ID | Author/Program | Comment | Date |
---|---|---|---|
1301 | stefan | TODO: skip inner classes | 2016-09-23 19:18:36 |
Snippet ID: | #1004051 |
Snippet name: | findFunctionDefs (finds static functions, LIVE in #759) |
Eternal ID of this version: | #1004051/14 |
Text MD5: | 991b5de70b6bc732582100d275abf574 |
Transpilation MD5: | 6af53dcd03c9257cfc552fa4650042fb |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-10 00:13:35 |
Source code size: | 1295 bytes / 42 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 949 / 1475 |
Version history: | 13 change(s) |
Referenced in: | [show references] |