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

27
LINES

< > BotCompany Repo | #1025303 - tok_selfType - "selfType" to enclosing class name

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

Libraryless. Click here for Pure Java version (2678L/17K).

svoid tok_selfType(L<S> tok) {
  int i;
  mainLoop: while ((i = jfind(tok, "selfType <id>")) >= 0) {
    // Now find class name by going backwards.
    
    int j = i, level = 1;
    while (j > 0 && level > 0) {
      S t = tok.get(j);
      if (t.equals("}")) ++level;
      if (t.equals("{")) --level;
      j -= 2;
    }
    
    // search for class name
    while (j > 0) {
      S t = tok.get(j);
      if (t.equals("class")) {
        String className = tok.get(j+2);
        tok.set(i, className);
        
        continue mainLoop;
      }
      j -= 2;
    }
    tok.set(i, "Object"); // avoid endless loop
  }
}

Author comment

Began life as a copy of #1023533

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1025303
Snippet name: tok_selfType - "selfType" to enclosing class name
Eternal ID of this version: #1025303/5
Text MD5: 0e68eebc554a9f417429817ee87d1f43
Transpilation MD5: 524888d94e35079e5a363df46f3f1a6a
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-20 13:53:35
Source code size: 648 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 21 / 59
Version history: 4 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1025303 & http://1025303.tinybrain.de