Transpiled version (8055L) is out of date.
1 | svoid test_tok_eventFunctions() {
|
2 | // no args |
3 | testTranspilationFunction tok_eventFunctions( |
4 | "event blubb;", [[ |
5 | transient Set<Runnable> onBlubb; |
6 | public selfType onBlubb(Runnable r) { onBlubb = createOrAddToSyncLinkedHashSet(onBlubb, r); this; }
|
7 | public selfType removeBlubbListener(Runnable r) { main remove(onBlubb, r); this; }
|
8 | public void blubb() { if (onBlubb != null) for (listener : onBlubb) pcallF_typed(listener); }
|
9 | ]]); |
10 | |
11 | // with args |
12 | testTranspilationFunction tok_eventFunctions( |
13 | "event newX(X x);", [[ |
14 | transient Set<IVF1<X>> onNewX; |
15 | public selfType onNewX(IVF1<X> f) { onNewX = createOrAddToSyncLinkedHashSet(onNewX, f); this; }
|
16 | public selfType removeNewXListener(IVF1<X> f) { main remove(onNewX, f); this; }
|
17 | public void newX(X x) { if (onNewX != null) for (listener : onNewX) pcallF_typed(listener, x); }
|
18 | ]]); |
19 | |
20 | // "on" prefix handled correctly |
21 | testTranspilationFunction tok_eventFunctions( |
22 | "event onBlubb;", [[ |
23 | transient Set<Runnable> onBlubb; |
24 | public selfType onBlubb(Runnable r) { onBlubb = createOrAddToSyncLinkedHashSet(onBlubb, r); this; }
|
25 | public selfType removeBlubbListener(Runnable r) { main remove(onBlubb, r); this; }
|
26 | public void blubb() { if (onBlubb != null) for (listener : onBlubb) pcallF_typed(listener); }
|
27 | ]]); |
28 | |
29 | // "fire" prefix handled correctly |
30 | testTranspilationFunction tok_eventFunctions( |
31 | "event fireBlubb;", [[ |
32 | transient Set<Runnable> onBlubb; |
33 | public selfType onBlubb(Runnable r) { onBlubb = createOrAddToSyncLinkedHashSet(onBlubb, r); this; }
|
34 | public selfType removeBlubbListener(Runnable r) { main remove(onBlubb, r); this; }
|
35 | public void fireBlubb() { if (onBlubb != null) for (listener : onBlubb) pcallF_typed(listener); }
|
36 | ]]); |
37 | |
38 | // firing functions can now have a body |
39 | testTranspilationFunction tok_eventFunctions( |
40 | "event newX(X x) { bla; }", [[
|
41 | transient Set<IVF1<X>> onNewX; |
42 | public selfType onNewX(IVF1<X> f) { onNewX = createOrAddToSyncLinkedHashSet(onNewX, f); this; }
|
43 | public selfType removeNewXListener(IVF1<X> f) { main remove(onNewX, f); this; }
|
44 | public void newX(X x) { bla; if (onNewX != null) for (listener : onNewX) pcallF_typed(listener, x); }
|
45 | ]]); |
46 | |
47 | // static event |
48 | testTranspilationFunction tok_eventFunctions( |
49 | "static event blubb;", [[ |
50 | static transient Set<Runnable> onBlubb; |
51 | public static selfType onBlubb(Runnable r) { onBlubb = createOrAddToSyncLinkedHashSet(onBlubb, r); this; }
|
52 | public static selfType removeBlubbListener(Runnable r) { main remove(onBlubb, r); this; }
|
53 | public static void blubb() { if (onBlubb != null) for (listener : onBlubb) pcallF_typed(listener); }
|
54 | ]]); |
55 | |
56 | S s = "void event aka setEvent() {}";
|
57 | testTranspilationFunction tok_eventFunctions(s, s); |
58 | } |
Began life as a copy of #1025409
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1027846 |
| Snippet name: | test_tok_eventFunctions |
| Eternal ID of this version: | #1027846/21 |
| Text MD5: | a74166140c506b1993bcb03dfd226077 |
| Author: | stefan |
| Category: | javax / transpiling |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-11-26 17:55:17 |
| Source code size: | 2912 bytes / 58 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 516 / 834 |
| Version history: | 20 change(s) |
| Referenced in: | [show references] |