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

77
LINES

< > BotCompany Repo | #1033186 // Tok_MethodDecl

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

Transpiled version (6626L) is out of date.

sclass Tok_MethodDecl {
  LS tok;
  int iStart, iModifiers, iTypeArgs, iType, iEndOfType, iJavaXMod;
  int iName, iOpening, iClosing;
  gettable S name;
  new LS allNames;
  int iBody;
  bool parsed;
  
  *(LS *tok, int *iStart) {
    iOpening = indexOf(tok, iStart, "(");
    if (iOpening < 0) ret;
    iName = iOpening-2;
    name = main get(tok, iName);
    allNames.add(name);
    if (!isIdentifier(name)) ret;
    
    while (eqGet(tok, iName-2, "aka")
      && isIdentifier(main get(tok, iName-2))) {
      iName -= 4;
      name = main get(tok, iName);
      allNames.add(name);
    }
    
    // find end of arguments
    iClosing = findEndOfBracketPart2(tok, iOpening)-1;
    
    // find end of block or semicolon
    iBody = indexOfAny(tok, iClosing, "{", ";");

    // find javax modifiers, return type & modifiers
    iJavaXMod = tok_leftScanJavaxModifiers(tok, iName);
    iEndOfType = iJavaXMod;
    iType = tok_leftScanType(tok, iJavaXMod);
    iTypeArgs = tok_leftScanTypeArgsOpt(tok, iType);
    iModifiers = leftScanModifiers(tok, iTypeArgs);
    
    iStart = iModifiers;
    reverseInPlace(allNames);
    set parsed;
  }

  simplyCached LS args_unparsed() {
    ret tok_parseArgsDeclList2(subList(tok, iOpening+1, iClosing));
  }
    
  // return type
  LS tokType() {
    ret subList(tok, iType-1, iName);
  }
  
  S type() { ret join(tokType()); }
  
  simplyCached bool isVoid() {
    ret containsOneOf(codeTokens(tokType()), javaxVoidAliases());
  }
    
  LS tokModifiers() {
    ret subList(tok, iStart, iName-1);
  }
  
  bool get() { ret parsed; }
  
  simplyCached L<Tok_ArgDecl> argDecls() {
    ret tok_argDecls(subList(tok, iOpening+1, iClosing));
  }
  
  LS argNames() { ret map(argDecls(), a -> a.name); }
  
  bool hasBody() { ret eqGet(tok, iBody, "{"); }
  
  simplyCached int iEndOfBody() {
    ret hasBody() ? tok_scanBlock_idx(tok, iBody) : iBody+2;
  }
  
  int iEnd() { ret iEndOfBody(); }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1033186
Snippet name: Tok_MethodDecl
Eternal ID of this version: #1033186/22
Text MD5: 9c77199e1ba1cbf48ec3acdafa4d4043
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-16 02:26:42
Source code size: 2011 bytes / 77 lines
Pitched / IR pitched: No / No
Views / Downloads: 151 / 255
Version history: 21 change(s)
Referenced in: [show references]