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

58
LINES

< > BotCompany Repo | #1027846 // test_tok_eventFunctions

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

Transpiled version (8055L) is out of date.

svoid test_tok_eventFunctions() {
  // no args
  testTranspilationFunction tok_eventFunctions(
    "event blubb;", [[
      transient Set<Runnable> onBlubb;
      public selfType onBlubb(Runnable r) { onBlubb = createOrAddToSyncLinkedHashSet(onBlubb, r); this; }
      public selfType removeBlubbListener(Runnable r) { main remove(onBlubb, r); this; }
      public void blubb() { if (onBlubb != null) for (listener : onBlubb) pcallF_typed(listener); }
    ]]);
    
  // with args
  testTranspilationFunction tok_eventFunctions(
    "event newX(X x);", [[
      transient Set<IVF1<X>> onNewX;
      public selfType onNewX(IVF1<X> f) { onNewX = createOrAddToSyncLinkedHashSet(onNewX, f); this; }
      public selfType removeNewXListener(IVF1<X> f) { main remove(onNewX, f); this; }
      public void newX(X x) { if (onNewX != null) for (listener : onNewX) pcallF_typed(listener, x); }
    ]]);
    
  // "on" prefix handled correctly
  testTranspilationFunction tok_eventFunctions(
    "event onBlubb;", [[
      transient Set<Runnable> onBlubb;
      public selfType onBlubb(Runnable r) { onBlubb = createOrAddToSyncLinkedHashSet(onBlubb, r); this; }
      public selfType removeBlubbListener(Runnable r) { main remove(onBlubb, r); this; }
      public void blubb() { if (onBlubb != null) for (listener : onBlubb) pcallF_typed(listener); }
    ]]);
    
  // "fire" prefix handled correctly
  testTranspilationFunction tok_eventFunctions(
    "event fireBlubb;", [[
      transient Set<Runnable> onBlubb;
      public selfType onBlubb(Runnable r) { onBlubb = createOrAddToSyncLinkedHashSet(onBlubb, r); this; }
      public selfType removeBlubbListener(Runnable r) { main remove(onBlubb, r); this; }
      public void fireBlubb() { if (onBlubb != null) for (listener : onBlubb) pcallF_typed(listener); }
    ]]);
    
  // firing functions can now have a body
  testTranspilationFunction tok_eventFunctions(
    "event newX(X x) { bla; }", [[
      transient Set<IVF1<X>> onNewX;
      public selfType onNewX(IVF1<X> f) { onNewX = createOrAddToSyncLinkedHashSet(onNewX, f); this; }
      public selfType removeNewXListener(IVF1<X> f) { main remove(onNewX, f); this; }
      public void newX(X x) { bla; if (onNewX != null) for (listener : onNewX) pcallF_typed(listener, x); }
    ]]);
  
  // static event
  testTranspilationFunction tok_eventFunctions(
    "static event blubb;", [[
      static transient Set<Runnable> onBlubb;
      public static selfType onBlubb(Runnable r) { onBlubb = createOrAddToSyncLinkedHashSet(onBlubb, r); this; }
      public static selfType removeBlubbListener(Runnable r) { main remove(onBlubb, r); this; }
      public static void blubb() { if (onBlubb != null) for (listener : onBlubb) pcallF_typed(listener); }
    ]]);
    
  S s = "void event aka setEvent() {}";
  testTranspilationFunction tok_eventFunctions(s, s);
}

Author comment

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: 262 / 536
Version history: 20 change(s)
Referenced in: [show references]