Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

20
LINES

< > BotCompany Repo | #1017552 // tok_ifCast

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (5726L) is out of date.

svoid tok_ifCast(L<S> tok) {
  int i;
  while ((i = jfind_check cast(tok, "if (<id> cast <id>")) >= 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);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1017552
Snippet name: tok_ifCast
Eternal ID of this version: #1017552/24
Text MD5: 854fc5e971da13ac0e8e062b8ecefb94
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-02-21 16:49:20
Source code size: 863 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 481 / 633
Version history: 23 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1025425 - tok_ifRecordMatch
#1033639 - tok_insertCasts_noReTok
#1033873 - tok_castQuestionDot - actually misnamed. transpiles cast + ternary operator