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 to", "delegate ,")) >= 0) { Set 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) + "." + token; clearTokens(tok, i, repEnd+1); print("Replacing " + token + " with " + replacement + "."); int end = findEndOfBlock(tok, repEnd)-1; for ping (int j = repEnd+2; j < end; j += 2) if (tokens.contains(tok.get(j))) // skip if it's a field or method access && !(empty(get(tok, j-1)) && eqGet(tok, j-2, "."))) tok.set(j, replacement); reTok(tok, i, end); } }