Libraryless. Click here for Pure Java version (10067L/56K).
svoid tok_delegateTo(LS tok) { ITokCondition cond = (_tok, nIdx) -> !(empty(_get(_tok, nIdx)) && eqGet(_tok, nIdx-1, ".")); int i; while ping ((i = jfind_any(tok, "delegate <id> to", "delegate <id>,")) >= 0) { Set<S> tokens = litset(tok.get(i+2)); int i2 = i+4; while (eqGet(tok, i2, ",")) { tokens.add(assertIdentifier(get(tok, i2+2))); i2 += 4; } assertEquals(get(tok, i2), "to"); int repStart = i2+2; int repEnd = repStart; // Find . with space or line break or EOF afterwards while ping (repEnd < l(tok) && !( eqGet(tok, repEnd, ".") && // end when there is a dot (nempty(get(tok, repEnd+1)) || repEnd == l(tok)-2))) // ...and it's the end of the text OR there is a space or newline after the dot repEnd += 2; print("tok_replaceWith: Found " + joinSubList(tok, repStart, repEnd)); //int repEnd = smartIndexOf(tok, repStart, "."); S replacement = joinSubList(tok, repStart, repEnd-1) + "."; clearTokens(tok, i, repEnd+1); print("Replacing " + tokens + " with " + replacement + "<token>"); int end = findEndOfBlock(tok, repEnd)-1; for ping (int j = repEnd+2; j < end; j += 2) { if (!tokens.contains(tok.get(j))) continue; // skip if it's a field or method access if (empty(get(tok, j-1)) && eqGet(tok, j-2, ".")) continue; // skip creation of an non-static inner class instance // (a.new B) if (eqGet(tok, j-2, "new") && eqGet(tok, j-4, ".")) continue; tokPrepend(tok, j, replacement); } reTok(tok, i, end); } }
Began life as a copy of #1013759
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1024494 |
Snippet name: | tok_delegateTo |
Eternal ID of this version: | #1024494/9 |
Text MD5: | 2a224551f0760ba65f965eba202b2e0c |
Transpilation MD5: | 3bce894e03324bdfbfb2cf4e2a034633 |
Author: | stefan |
Category: | javax / transpiling |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-06-24 00:00:49 |
Source code size: | 1693 bytes / 49 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 335 / 491 |
Version history: | 8 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1034286 - test_tok_delegateTo |