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

50
LINES

< > BotCompany Repo | #1032213 // tok_expandMultiTypeArgument_v3

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

Transpiled version (4270L) is out of date.

svoid tok_expandMultiTypeArgument_v3(LS tok,
  int iArgStart, int iArgEnd, // start and end of argument
  S argName, S mainType, LPairS alts) {
  
  iArgEnd |= 1;

  int iOpening = lastIndexOf(tok, iArgStart, "("); // 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));
  LS _args1 = subList(tok, iOpening+1, iArgStart);
  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);
  
  new LS altFunctions;
  
  for (S altDecl, S conversionExpr : unpair alts) {
    if (tok_isSingleIdentifier(altDecl))
      altDecl += " \*argName*/";
      
    if (tok_isSingleIdentifier(conversionExpr))
      conversionExpr += "(\*argName*/)";
    
    S altHead = joinSubList(tok, iStart, iOpening+1)
      + joinWithComma(concatLists(
          args1,
          ll(altDecl),
          args2)) + ")";
    altFunctions.add(altHead + " { "
      + (isVoid ? "" : "return ") + name + "(" + 
        joinWithComma(concatLists(
          map tok_lastIdentifier(args1),
          ll(conversionExpr),
          map tok_lastIdentifier(args2))) + "); }\n");
  }
        
  replaceTokens_reTok(tok, iArgStart|1, iArgEnd, mainType + " " + argName);
  tokPrepend_reTok(tok, iStart, lines(altFunctions));
}

Author comment

Began life as a copy of #1032175

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032213
Snippet name: tok_expandMultiTypeArgument_v3
Eternal ID of this version: #1032213/4
Text MD5: 3a746f6ddb4ccf0d4a879271054da6bd
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-06-27 10:33:15
Source code size: 1823 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 202 / 293
Version history: 3 change(s)
Referenced in: [show references]