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.

1  
// Yay funny naming time! ("shipping")
2  
/* transient event interface onRecordAdded as OnRecordAdded shipping RecordAdded;
3  
   => stuff
4  
*/
5  
svoid tok_eventInterfaces(LS tok) {
6  
  int i;
7  
8  
  while ((i = jfind(tok, "transient event interface <id> as <id> shipping <id>;")) >= 0) {
9  
    int iStart = i;
10  
    i += 2;
11  
    int iSemicolon = indexOf(tok, iStart, ";");
12  
    S listenerType = get(tok, i+4);
13  
    S method = get(tok, i+8);
14  
    S eventType = get(tok, i+12);
15  
    
16  
    replaceTokens_reTok(tok, iStart, iSemicolon+1, 
17  
      tok_formatDollarVars([[
18  
        interface $intf {
19  
          void $method($eventType event);
20  
        }
21  
        
22  
        transient L<$Listener> $listeners;
23  
        synchronized selfType $add($Listener l) { $listeners = addOrCreate($listeners, l); this; }
24  
        synchronized Cl<$Listener> $listeners() { ret cloneList($listeners); }
25  
        void $method($Event event) { for (l : $listeners()) pcall { l?.$method(event); } }
26  
      ]],
27  
        +method,
28  
        intf := listenerType,
29  
        +eventType,
30  
        Event := eventType,
31  
        add := method,
32  
        Listener := listenerType,
33  
        listeners := method + "_listeners"));
34  
  }
35  
}

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: 181 / 255
Version history: 9 change(s)
Referenced in: [show references]