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); int start = iClosing+2, end = tok_findEndOfStatement(tok, start); tok.set(i+6, "instanceof"); // replace "var" with "((Type) var)" in enclosed block // unless it's another cast expression or an assignment print(+iEndOfType, +iClosing, +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.set(j, "((" + type + ") " + var + ")"); reTok(tok, i+6, end); } }