// Note: the variable names must match the record field names // as we still need a way to find the field names from here static void tok_ifRecordMatch(LS tok) { int i; while ((i = jfind_check is(tok, "if is (")) >= 0) { int iOpening = indexOf(tok, i, "("); int iClosing = indexOf(tok, iOpening+2, ")"); S var = tok.get(i+2), className = tok.get(i+6); S cast = "((" + className + ") " + var + ")"; int start = iClosing+2; tok_statementToBlock(tok, start); int end = findEndOfStatement(tok, start); StringBuilder statement = new("if (\*var*/ instanceof \*className*/"); new StringBuilder decls; LPairS vars = tok_typesAndNamesOfParams(subList(tok, iOpening+1, iClosing)); for (PairS v : vars) { S type = v.a, name = v.b; S nonPrim = tok_toNonPrimitiveTypes(type); if (!tok_typeIsObject(type)) statement.append(" && \*cast*/.\*name*/ instanceof \*nonPrim*/"); decls.append("\n\*type*/ \*name*/ = cast \*cast*/.\*name*/;"); } replaceTokens_reTok(tok, i, start+1, statement + ") {" + decls); } }