svoid tok_ifCast(L tok) { int i; while ((i = jfind_check cast(tok, "if ( cast ")) >= 0) { int iEndOfType = indexOfAny(tok, i, ")", "&"); int iClosing = tok_endOfExpression(tok, i+4)+1; S var = tok.get(i+4), type = joinSubList(tok, i+8, iEndOfType-1); S rawType = tok_dropTypeParameters(type); int start = iClosing+2, end = tok_findEndOfStatement(tok, start); replaceTokens(tok, i+6, iEndOfType-1, "instanceof " + rawType); // replace "var" with "((Type) var)" in enclosed block // unless it's another cast expression or an assignment printVars(+iEndOfType, +iClosing, iClosing := get(tok, iClosing), +start, start := get(tok, start), +end, lTok := l(tok)); end = min(end, l(tok)); tok_insertCasts_noReTok(tok, iEndOfType, end, var, type); reTok(tok, i+6, end); } }