Libraryless. Click here for Pure Java version (6335L/37K).
| 1 | // Note: the variable names must match the record field names | 
| 2 | // as we still need a way to find the field names from here | 
| 3 | static void tok_ifRecordMatch(LS tok) {
 | 
| 4 | int i; | 
| 5 |   while ((i = jfind_check is(tok, "if <id> is <id>(")) >= 0) {
 | 
| 6 |     int iOpening = indexOf(tok, i, "(");  
 | 
| 7 | int iClosing = indexOf(tok, iOpening+2, ")"); | 
| 8 | S var = tok.get(i+2), className = tok.get(i+6); | 
| 9 |     S cast = "((" + className + ") " + var + ")";
 | 
| 10 | int start = iClosing+2; | 
| 11 | tok_statementToBlock(tok, start); | 
| 12 | int end = findEndOfStatement(tok, start); | 
| 13 |     StringBuilder statement = new("if (\*var*/ instanceof \*className*/");
 | 
| 14 | new StringBuilder decls; | 
| 15 | LPairS vars = tok_typesAndNamesOfParams(subList(tok, iOpening+1, iClosing)); | 
| 16 |     for (PairS v : vars) {
 | 
| 17 | S type = v.a, name = v.b; | 
| 18 | S nonPrim = tok_toNonPrimitiveTypes(type); | 
| 19 | if (!tok_typeIsObject(type)) | 
| 20 |         statement.append(" && \*cast*/.\*name*/ instanceof \*nonPrim*/");
 | 
| 21 |       decls.append("\n\*type*/ \*name*/ = cast \*cast*/.\*name*/;");
 | 
| 22 | } | 
| 23 |     replaceTokens_reTok(tok, i, start+1, statement + ") {" + decls);
 | 
| 24 | } | 
| 25 | } | 
Began life as a copy of #1017552
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1025425 | 
| Snippet name: | tok_ifRecordMatch | 
| Eternal ID of this version: | #1025425/9 | 
| Text MD5: | 7d5bc6e6902f8c7aa0c6e202e3ae3128 | 
| Transpilation MD5: | 5d50f2d61aa26d2083d75bac3fef818a | 
| Author: | stefan | 
| Category: | javax / transpiling | 
| Type: | JavaX fragment (include) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2019-09-29 00:17:03 | 
| Source code size: | 1116 bytes / 25 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 647 / 907 | 
| Version history: | 8 change(s) | 
| Referenced in: | [show references] |