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

18
LINES

< > BotCompany Repo | #1017552 - tok_ifCast

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

Libraryless. Click here for Pure Java version (2764L/18K).

static void tok_ifCast(L<S> tok) {
  int i;
  while ((i = jfind_check cast(tok, "if (<id> cast <id>")) >= 0) {
    int iClosing = indexOf(tok, i, ")");
    S var = tok.get(i+4), type = joinSubList(tok, i+8, iClosing-1);
    int start = iClosing+2, end = findEndOfStatement(tok, start);
    tok.set(i+6, "instanceof");
    
    // replace "var" with "((Type) var)" in enclosed block
    // unless it's another cast expression
    
    for (int j = start; j < end; j += 2)
      if (eq(tok.get(j), var) && neqGet(tok, j-2, ".")
        && neqGet(tok, j+2, "cast"))
        tok.set(j, "((" + type + ") " + var + ")");
    reTok(tok, i+6, end);
  }
}

download  show line numbers  debug dex   

Travelled to 10 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1017552
Snippet name: tok_ifCast
Eternal ID of this version: #1017552/8
Text MD5: a88dbd6739caa57844a1a4acf44e7617
Transpilation MD5: df7932ac74f546886c41913cac2a943c
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-28 23:00:00
Source code size: 663 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 153 / 173
Version history: 7 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1017552 & http://1017552.tinybrain.de