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

35
LINES

< > BotCompany Repo | #1032260 // test_tok_ifCast

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

Transpiled version (4355L) is out of date.

svoid test_tok_ifCast(bool optimized default true) {
  testTranspilationFunction tok_ifCast(
    "if (a cast B) a = a.x; print(a);",
    "if (a instanceof B) a = ((B) a).x; print(a);",
    "if (a cast B && a.y) a = a.x; print(a);",
    "if (a instanceof B && ((B) a).y) a = ((B) a).x; print(a);",
    [[
      if (contents cast S && isRelativeOrAbsoluteURL(contents))
        ret hstylesheetsrc(contents);
      else    
        ret htag("style", contents);
    ]],
    [[
      if (contents instanceof S && isRelativeOrAbsoluteURL((S) contents))
        ret hstylesheetsrc((S) contents);
      else    
        ret htag("style", contents);
    ]],
    "if (a cast int[]) { x = a; } if (a cast long[]) { y = a; }",
    optimized ? "if (a instanceof int[]) { x = (int[]) a; }"
      + " if (a instanceof long[]) { y = (long[]) a; }"
      : "if (a instanceof int[]) { x = ((int[]) a); }"
      + " if (a instanceof long[]) { y = ((long[]) a); }",
    "if (a cast B) a = x(a);",
    "if (a instanceof B) a = x((B) a);",
    
    // type parameters (slightly dirty)
    "if (a cast Map<O>) b = a;",
    "if (a instanceof Map) b = (Map<O>) a;",
    
    // variable name = function name
    "if (map cast Map) ret map(map);",
    "if (map instanceof Map) ret map((Map) map);",
  );
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, wnsclhtenguj

No comments. add comment

Snippet ID: #1032260
Snippet name: test_tok_ifCast
Eternal ID of this version: #1032260/12
Text MD5: a394c52cbfb0519b1f9d787e1775a8bb
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-23 00:38:16
Source code size: 1313 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 176 / 288
Version history: 11 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1032612 - test_tok_shortLambdas
#1033874 - test_tok_castQuestionDot