Transpiled version (4269L) is out of date.
// only one multi-type argument per declaration for now // also allows only one combo right now (File/S with newFile) // example: // sS loadTextFile(File/S file) { ... } svoid tok_multiTypeArguments(LS tok) { int i; while ((i = jfind(tok, "File/<id> <id>", (_tok, nIdx) -> eqGetOneOf(_tok, nIdx+5, "S", "String"))) >= 0) { int iOpening = lastIndexOf(tok, i, "("); // TODO: brackets int iClosing = findEndOfBracketPart2(tok, iOpening)-1; // function name int iName = iOpening-2; S name = assertIdentifier(get(tok, iName)); int iType = tok_leftScanType(tok, iName); int iStart = tok_leftScanTypeArgsOpt(tok, iType); iStart = leftScanModifiers(tok, iStart); //print("Found method head: " + joinSubList(tok, iStart, iClosing+1)); int iArgEnd = i+8; // comma or closing bracket LS _args1 = subList(tok, iOpening+1, i); LS _args2 = subList(tok, iArgEnd+1, iClosing); LS args1 = tok_parseArgsDeclList2(_args1); LS args2 = tok_parseArgsDeclList2(_args2); LS type = subList(tok, iType-1, iName); bool isVoid = containsOneOf(codeTokens(type), javaxVoidAliases()); //printVars(+expr, +_args1, +_args2, +args1, +args2, +type, +isVoid); S argName = tok.get(i+6); S mainType = tok.get(i), altType = tok.get(i+4); S converter = "newFile"; S expr = converter + "(" + argName + ")"; S rewrittenHead = joinSubList(tok, iStart, iOpening+1) + joinWithComma(concatLists( args1, ll(altType + " " + argName), args2)) + ")"; replaceTokens_reTok(tok, i, i+7, mainType + " " + argName); tokPrepend_reTok(tok, iStart, rewrittenHead + " { " + (isVoid ? "" : "return ") + name + "(" + joinWithComma(concatLists( map tok_lastIdentifier(args1), ll(expr), map tok_lastIdentifier(args2))) + "); }\n"); } }
Began life as a copy of #1027996
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1031905 |
Snippet name: | tok_multiTypeArguments [replaced by tok_multiTypeArguments_v2] |
Eternal ID of this version: | #1031905/7 |
Text MD5: | da67e27c87a9b32ed58dd736b1c35aa7 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-08-17 14:27:59 |
Source code size: | 1923 bytes / 47 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 157 / 234 |
Version history: | 6 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1032172 - tok_expandMultiTypeArgument #1032173 - tok_multiTypeArguments_v2 [certain multi-typed arguments for functions, run after most JavaX translations, LIVE] |