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)); for (int j = iEndOfType; j < end; j += 2) if (eq(tok.get(j), var) && neqGet(tok, j-2, ".") && neqGet(tok, j+2, "cast") && !tok_isAssignment(tok, j+2)) tok_insertCast(tok, j, type); reTok(tok, i+6, end); } }