1 | static bool allVarNamesWithTypes_debug; |
2 | |
3 | // TODO: array brackets |
4 | static SS allVarNamesWithTypes(L<S> tok) {
|
5 | bool debug = allVarNamesWithTypes_debug; |
6 | Map<Int, Int> bracketMap = getBracketMap(tok); |
7 | SS vars = litorderedmap(); |
8 | |
9 | int i = 1; |
10 | while (i < l(tok)) {
|
11 | while (isJavaModifier(tok.get(i))) i += 2; |
12 | |
13 | ... |
14 | |
15 | for (int i = 3; i < tok.size(); i += 2) {
|
16 | S t = tok.get(i); |
17 | if (eqOneOf(t, "=", ";", ",")) {
|
18 | S v = tok.get(i-2); |
19 | if (isIdentifier(v)) |
20 | varNames.add(v); |
21 | if (eq(t, "=")) {
|
22 | i = scanToEndOfInitializer(tok, bracketMap, i)+1; |
23 | assertTrue(odd(i)); |
24 | } |
25 | } else if (eq(t, "<")) {
|
26 | i = findEndOfTypeArgs(tok, i)+1; |
27 | if (debug) |
28 | print("Skipped type args: " + struct(subList(tok, i)));
|
29 | } else if (eq(t, "{"))
|
30 | i = findEndOfBlock(tok, i)+1; // skip function/class bodies |
31 | } |
32 | return vars; |
33 | } |
34 | |
35 | static SS allVarNamesWithTypes(S text) {
|
36 | ret allVarNamesWithTypes(javaTok(text)); |
37 | } |
Began life as a copy of #1005504
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1009921 |
| Snippet name: | allVarNamesWithTypes - find all variable/field declarations in a block/class [dev.] |
| Eternal ID of this version: | #1009921/3 |
| Text MD5: | 7b0ce60958ef76ee39d5a5fce6cae3cb |
| Author: | stefan |
| Category: | javax / parsing |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-08-26 04:02:09 |
| Source code size: | 1017 bytes / 37 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 685 / 694 |
| Version history: | 2 change(s) |
| Referenced in: | [show references] |