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

35
LINES

< > BotCompany Repo | #1032995 // tok_eventInterfaces

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

Transpiled version (4643L) is out of date.

// Yay funny naming time! ("shipping")
/* transient event interface onRecordAdded as OnRecordAdded shipping RecordAdded;
   => stuff
*/
svoid tok_eventInterfaces(LS tok) {
  int i;

  while ((i = jfind(tok, "transient event interface <id> as <id> shipping <id>;")) >= 0) {
    int iStart = i;
    i += 2;
    int iSemicolon = indexOf(tok, iStart, ";");
    S listenerType = get(tok, i+4);
    S method = get(tok, i+8);
    S eventType = get(tok, i+12);
    
    replaceTokens_reTok(tok, iStart, iSemicolon+1, 
      tok_formatDollarVars([[
        interface $intf {
          void $method($eventType event);
        }
        
        transient L<$Listener> $listeners;
        synchronized selfType $add($Listener l) { $listeners = addOrCreate($listeners, l); this; }
        synchronized Cl<$Listener> $listeners() { ret cloneList($listeners); }
        void $method($Event event) { for (l : $listeners()) pcall { l?.$method(event); } }
      ]],
        +method,
        intf := listenerType,
        +eventType,
        Event := eventType,
        add := method,
        Listener := listenerType,
        listeners := method + "_listeners"));
  }
}

Author comment

Began life as a copy of #1027845

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1032995
Snippet name: tok_eventInterfaces
Eternal ID of this version: #1032995/10
Text MD5: b0402bc3e370f4f5ed3a0a8a63e6072f
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-11 10:56:22
Source code size: 1186 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 179 / 252
Version history: 9 change(s)
Referenced in: [show references]