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

13
LINES

< > BotCompany Repo | #1031988 // tok_optionalFields

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

Libraryless. Click here for Pure Java version (3828L/22K).

// optional S bla;
// => S bla() { ret getOpt(this, "bla"); }
//    void bla(S bla) { setOpt(this, "bla", bla); }
svoid tok_optionalFields(LS tok) {
  for (int i : jfindAll_reverse(tok, "optional <id>")) {
    int iSemicolon = tok_endOfStatement(tok, i)-1;
    S var = tok.get(iSemicolon-2);
    S type = joinSubList(tok, i+2, iSemicolon-3);
    tokReplace_reTok(tok, i, iSemicolon+1,
      "public \*type*/ \*var*/() { ret (\*type*/ getOpt(this, \*quote(var)*/); }\n" +
      "public void var(\*type*/ var) { setOpt(this, \*quote(var)*/, \*var*/); }");
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1031988
Snippet name: tok_optionalFields
Eternal ID of this version: #1031988/5
Text MD5: 3fd9ccbcf405c8c54d9ebf5028b545f4
Transpilation MD5: dae22e46d78f048fd61b8d7f01231bc9
Author: stefan
Category: javax / image reconstruction [dev.]
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-06 07:38:51
Source code size: 571 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 216 / 296
Version history: 4 change(s)
Referenced in: [show references]